note 56454 deleted from language.references.pass by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 Jan 2010 13:20:12 +0000 |
| Subject: | note 56454 deleted from language.references.pass by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165422@lists.php.net to get a copy of this message | ||
Note Submitter: bobbykjack at hotmail dot com
----
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.