Folks,
I've always thought the syntax for using references as kind of weird...
Anyway, given the following code:
<?php
class Node {
var $data;
var $next;
function getData(){
return $this->data;
}
function setData($v){
$this->data = $v;
}
function Node($d) {
$this->setData($d);
}
function setChild(&$n) {
$this->next = $n;
}
}
$node1 =& new Node('hello');
$node2 =& new Node('goodbye');
$node1->setChild($node2);
$node2->setData('adios');
echo $node2->getData().' ? '.$node1->next->getData();
?>
why does $node1->next->getData() == 'adios'? I think that somewhere along the way, I get a copy rather than a reference, but I honestly don't see it.
I have read the manual, on Objects, References, etc... and it all makes sense....until I write the above!
Help me, I'm losing sanity points....