Jump to content

[SOLVED] Desparation: References do not work as expected


Recommended Posts

Hello guys, first post here.

I am really desparate about how references (do not) work in PHP.

Here's a code snippet:

[code]
var $data;
var $_children;
var $_uniqueNames;

function &add(&$child) {
$name = $child->data->name;
if (array_key_exists($name, $this->_uniqueNames)) {
return $this->_uniqueNames[$name];
}
$this->_children[] =& $child;
$this->_uniqueNames[$name] =& $child; // we register the name
$true = TRUE;
return $true;
}
[/code]

This is part of a simple Node class prepared to build trees. A Node remembers the names of its children and refuses to add a new child with a name already registered. Everything seems to work except the return value in case there is an attempt to add a child with an already registered name -- my client code always gets NULL whatever I do!
I would appreciate any idea of why is that and how can I fix it, thanks in advance!
Yassen
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.