|
Posted by Ivαn Sαnchez Ortega on 03/01/07 16:54
> $item = new CUserItem(1);
> $item2 = new CUserItem(2);
> $toc_items_arr[1] = $item;
> $item->addChild($item2);
> print $toc_items_arr[1]->numChildren(); // still prints zero!
>
> The "print" line should print out "1" because I have added a child.
> But it does not. What's going wrong? - Dave
You're assigning a copy og $item to $toc_items_arr[1], not a reference to
$item.
Thus, you are updating $item but not $toc_items_arr[1].
Please re-read the chapter on references in the PHP manual; after you've
done so, you'll probably understand what's going on. And then, by RTFM,
you'll learn to assing things by reference.
--
----------------------------------
IvΓ‘n SΓ‘nchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
Un ordenador no es un televisor ni un microondas, es una herramienta
compleja.
[Back to original message]
|