When i add a node to a tree, i store its parent address (i thought so) in it:
-- Client --
$parent = new Node();
$child = new Node();
$parent->add($child)
-- Class Node --
function add($child) {
$this->setParent(&$this);
$this->children[] = $child;
}
function setParent($ref_parent) {
$this->ref_parent = $ref_parent;
}
But when i try to echo $child->ref_parent, it fails on “Catchable fatal error: Object of class Node could not be converted to string…”, i use & cos i don’t want to store parent object in its child, but seems don’t work, any idea?
No, no, no. You can’t break down to such low level concepts like memory addresses in PHP. You can’t get a memory address of a value.
$thisand other objects are always passed by reference, so the object doesn’t get copied. At least in PHP5.