Having problems with storing a reference to the parent
Posted: Tue Jan 20, 2004 1:06 pm
I'm having problems with storing a reference to the parent in the child, here's an example demonstrating how I'm doing (I've tried a lot of other things as well thou)
What I of course would have expected from this example is that it would output modified 2 times.
Grateful for any help
Code: Select all
<?php
class C1
{
var $ref;
function C1()
{
}
}
class C2
{
var $var;
var $child;
function C2()
{
$this->var = 'original';
$this->child = new C1();
$this->child->ref = &$this;
}
}
$test = new C2();
$test->var = 'modified';
print $test->child->ref->var;
print '<br />';
print $test->var;
/*
this outputs:
original
modified
What I want is to store the reference of the parent in the child, is that possible in some way?
*/
?>Grateful for any help