|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[1999-08-16 16:14 UTC] dom at recoil dot org
Whenever I try to build a self referential structure,
information is lost after two nodes in the chain.
The following code shows that the structures can never
be more than two nodes deep.
<?
class Test
{
var $next;
function add($next)
{
$this->next = $next;
return $next;
}
function dump()
{
echo "Test!<br>";
$this->next->dump();
}
}
$test = new Test;
$next = $test->add(new Test);
$next = $test->add(new Test);
$next = $test->add(new Test);
$test->dump();
?>
This code causes the following error with both
php3 and php4b2:
Test!
Test!
Fatal error: Call to a member function on a non-object in /home/dom/public_html
/treetest/test.php3 on line 19
Configure line was:
./configure --with-mysql --with-apache=../apache_1.3.6 --enable-track-vars --with-xml
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 12:00:01 2025 UTC |
Whenever I try to build a self referential structure, information is lost after two nodes in the chain. The following code shows that the structures can never be more than two nodes deep. <? class Test { var $next; function add($next) { $this->next = $next; return $next; } function dump() { echo "Test!<br>"; $this->next->dump(); } } $test = new Test; $next = $test->add(new Test); $next = $next->add(new Test); $next = $next->add(new Test); $test->dump(); ?> This code causes the following error with both php3 and php4b2: Test! Test! Fatal error: Call to a member function on a non-object in /home/dom/public_html /treetest/test.php3 on line 19 Configure line was: ./configure --with-mysql --with-apache=../apache_1.3.6 --enable-track-vars --with-xml