note 56454 added to language.references.pass
| From: | bobbykjack at hotmail dot com | Date: | Fri, 02 Sep 2005 22:44:00 +0000 |
| Subject: | note 56454 added to language.references.pass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94680@lists.php.net to get a copy of this message | ||
In response to mogmios, I think the problem may be similar to one I experienced. It seems that
reference parameters cannot be assigned a default value and, taking into account what can be passed
by reference, the only way I could achieve this functionality was with the following code:
<?php
class tree
{
var $parentNode;
var $childNodes;
function tree(&$parentNode)
{
if ($parentNode)
$this->parentNode =& $parentNode;
}
}
$null = '';
$parent = new tree($null);
$child = new tree($parent);
echo '<pre>';print_r($child);echo '</pre>';
?>
It's a nasty hack, but I cannot find a good alternative. The above script produces the
following output:
tree Object
(
[parentNode] => tree Object
(
[parentNode] =>
[childNodes] =>
)
[childNodes] =>
)
which is sparse, but technically correct (you can test this by expanding the implementation and
making use of $childNodes).
Note that this was tested under PHP 4.3.10 and PHP 5 has almost certainly changed this behaviour.
----
Manual Page -- http://www.php.net/manual/en/language.references.pass.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56454
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56454&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56454&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56454&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56454&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56454&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56454&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56454&report=yes
Search -- http://master.php.net/manage/user-notes.php