Lets say ObjectA acts as a container for ObjectB. ObjectA could be a database connection object, and ObjectB a numnch of tables, say.
My instinct is to do the following:
class ObjectA
{
var $children;
function addChild(&$child)
{
$this->children[] = &$child;
}
}
class ObjectB
{
var $parent;
function ObjectB(&$parent_o)
{
$this->parent = &$parent_o;
$parent_o->addChild(&$this);
}
}
But that last one doesn't work because you can't do &$this in a constructor (although it appeared to work in PHP 4.0.1pl2)!
So what is the recommended work-around for this? I don't want to do:
$a = new ObjectA;
$b = new ObjectB;
$a->addChild(&$b);
because that's not nice, but is there some cunning bodge that'll fix this problem? (Is this problem a bug?)