PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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)
<?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?
*/
?>
What I of course would have expected from this example is that it would output modified 2 times.