Hi all.
I’m stuck with trying to reference objects. Here is the scenario:
There are two objects Foo and Bar.
In Foo’s constructor the Bar is created and reference to Foo is passed to it.
The Bar’s constructor stores the reference to Foo.
Then Foo’s constructor calls Bar’s method that in turn uses the refence to Foo to call Foo’s method that updates Foo’s property:
[code=php]class Foo
{ var $test;
function add()
{ $this->test++;
}
function Foo()
{ $this->test = 0;
$bi = new Bar($this);
$bi->CallFoo();
}
}
class Bar
{ var $foo;
function CallFoo()
{ $this->foo->add();
}
function Bar(&$fp)
{ $this->foo = $fp;
}
}
$fi = new Foo();
print_r($fi->test);
I expect the print_r($fi->test) to return 1 not 0
?