class Tree (Memory_Array)
| From: | Martino Piccinato | Date: | Fri, 19 Dec 2003 14:21:00 +0000 |
| Subject: | class Tree (Memory_Array) | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-9726@lists.php.net to get a copy of this message | ||
Hi everybody,
it's some time I'm trying to use the class Tree. In particular I'm
having problems with the memory array implementation. I need to have a
tree in memory/array (no DB or files).
This simple code won't work:
<?php
require_once("Tree/Tree.php");
$array = Array();
$tree = Tree::setup('Memory_Array', &$array);
$root = $tree->add(Array('name' => 'root', 'comment' =>
'Root
element'));
$tree->add(Array('name' => 'first_node', 'comment' =>
'First node'),
$root);
$second_node = $tree->add(Array('name' => 'second_node',
'comment' =>
'Secon node'), $root);
$tree->add(Array('name' => 'second_node_child', 'comment' =>
'Second
node child'), $second_node);
$tree->setup();
$tree->varDump();
?>
it gives this error:
<table border="1"><tr><th>name</th>Memory.php: this->children
in
getFirstRoot() Array
(
)
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in
<b>/usr/share/pear/Tree/Memory.php</b> on line
<b>1285</b><br />
</tr><br />
<b>Warning</b>: Invalid argument supplied for foreach() in
<b>/usr/share/pear/Tree/Memory.php</b> on line
<b>1293</b><br />
</table>
By skimming through the code looks like what first fail is method
"getFirstRoot" in Memory.php and this because the data structure
$this->children is bad formed by Array.php and/or Memory.php.
I can also work on some patch for it but here I stop because I just fear
of having missed something very elementar about the whole thing and
maybe I'm just completely wrong. Has anybody already worked with this
class? experienced similar problems?
Thanks
Martino