Hi there.
I've attached a little sample I don't understand:
myC1 is constructed, that constructs myC2 in $this->theC2, which changes myC1's greeting to "bah". Then, $test->theC2->something(); should change myC1's greeting to "hulla", and finally, the greeting is printed.
Why does this sourcecode print "bah"?
<?
class myC1
{
var
$greeting;
var $theC2;
function sayHello()
{
echo $this->greeting;
}
function myC1()
{
$this->greeting="Howdy";
$this->theC2=new myC2($this);
}
}
class myC2
{
var $owner;
function myC2(&$owner)
{
$this->owner=&$owner;
$this->owner->greeting="bah";
}
function something()
{
$this->owner->greeting="hulla";
// This is supposed to change myC1's greeting to hulla, overwriting "bah".
}
}
$test=new myC1();
$test->theC2->something();
$test->sayHello();
?>