Hi, I have a simple tree class,
class mTree {
var $value = null;
var $children = array();
function mTree ($value) {
$this->value = $value;
}
function addChild ($value) {
$aux_node = & new mTree ($value);
$this->children [] =& $aux_node;
$this->displayTree("."
;
return $aux_node;
}
function getName (){
return $this->value;
}
function displayTree($indent){
echo($indent.$this->value."<br>"
;
echo("children".count($this->children)."<br>"
;
forEach ($this->children as $child){
$child->displayTree($indent."."
;
}
}
}
------------------------------------------------
I add a couple of test nodes thus,
$dirRoot = new Mtree("PROJECTS"
;
$newNode = $dirRoot->addChild("test1"
;
$newNode->addChild("test1_1"
;
my problem is, after adding "test1_1" the debuging code displays the tree from "test1" fine (i.e one child), but if I display the tree from $dirRoot, only "test1" seems to exist (i.e the child node vanishes). I assume I'm doing something stupid with references but Im lost...
Pete...
Digital Soma
class mTree {
var $value = null;
var $children = array();
function mTree ($value) {
$this->value = $value;
}
function addChild ($value) {
$aux_node = & new mTree ($value);
$this->children [] =& $aux_node;
$this->displayTree("."
return $aux_node;
}
function getName (){
return $this->value;
}
function displayTree($indent){
echo($indent.$this->value."<br>"
echo("children".count($this->children)."<br>"
forEach ($this->children as $child){
$child->displayTree($indent."."
}
}
}
------------------------------------------------
I add a couple of test nodes thus,
$dirRoot = new Mtree("PROJECTS"
$newNode = $dirRoot->addChild("test1"
$newNode->addChild("test1_1"
my problem is, after adding "test1_1" the debuging code displays the tree from "test1" fine (i.e one child), but if I display the tree from $dirRoot, only "test1" seems to exist (i.e the child node vanishes). I assume I'm doing something stupid with references but Im lost...
Pete...
Digital Soma