Problem with class and tree-like struct

From: Date: Sat, 07 Aug 2004 09:39:10 +0000
Subject: Problem with class and tree-like struct
Groups: php.general 
Request: Send a blank email to php-general+get-193073@lists.php.net to get a copy of this message
Hello! I made a class which should represent a tree-like structure (PHP 4.3.8). I made a root-nore and added 2 childs. The problem is that the childs are not added to the parent. Why? Martin class TreeItem { var $m_pParent; var $m_sName; var $m_arrChilds = array(); function TreeItem($pParent, $sName) { $this->m_pParent = $pParent; $this->m_sName = $sName; if ($pParent != NULL) $pParent->AddChild($this); } function AddChild($pTreeItem) { array_push($this->m_arrChilds, $pTreeItem); } } $root = new TreeItem(NULL, "Root"); $child1 = new TreeItem($root, "Child 1"); $child2 = new TreeItem($root, "Child 2"); print Count($root->m_arrChilds); // Outputs 0. Why????

« previous php.general (#193073) next »