Ahoj, který zápis je správně? Potřebuji přidat objekt $foo tříde Bar a nevím jak to správně udělat. Díky.
$foo = new Foo ();
$foo->bar = new Bar ($foo);
class Foo{
function constructor(){
this->bar = new Bar ($this);
}
}
Citace od: Host kdy 02. 04. 2017, 18:26:55
Ahoj, který zápis je správně? Potřebuji přidat objekt $foo tříde Bar a nevím jak to správně udělat. Díky.
$foo = new Foo ();
$foo->bar = new Bar ($foo);
class Foo{
function constructor(){
this->bar = new Bar ($this);
}
}
Lepší je
class A {
function __construct($foo) {
$this->foo = $foo;
}
function a() {
$this->foo->a();
}
}
$foo = new Foo();
$bar = new Bar($foo);