|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-01-01 20:52 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 10:00:02 2025 UTC |
Description: ------------ The problem is not that easy to explain. If you have two objects referencing each other, one of the references gets somehow lost. Look at the actual result, especially at the missing ampersands of object(test3)! Although I only use references in the script (sorry about it be longer than 20 lines) it seems that I get copies of the objects. Reproduce code: --------------- class Test1 { var $a; function Test1() { $this->a = new Test2(); } function &getTest2() { return $this->a; } } class Test2 { var $b; var $counter = 1; function Test2() { $this->b = new Test3($this); } function &getTest3() { return $this->b; } } class Test3 { var $p; function Test3(&$parent) { $parent->counter++; $this->p =& $parent; } function getCounter() { return $this->p->counter; } } $obj = new Test1(); $obj2 =& $obj->getTest2(); echo $obj2->counter; $obj2->counter++; $obj3 =& $obj2->getTest3(); echo $obj3->getCounter(); var_dump($obj); Expected result: ---------------- 23 object(test1)(1) { ["a"]=> &object(test2)(2) { ["b"]=> &object(test3)(1) { ["p"]=> &object(test2)(2) { ["b"]=> &object(test3)(1) { ["p"]=> &object(test2)(2) { ["b"]=> &object(test3)(1) { ["p"]=> *RECURSION* } ["counter"]=> int(3) } } ["counter"]=> int(3) } } ["counter"]=> int(3) } } Actual result: -------------- 22 object(test1)(1) { ["a"]=> &object(test2)(2) { ["b"]=> &object(test3)(1) { ["p"]=> &object(test2)(2) { ["b"]=> object(test3)(1) { ["p"]=> &object(test2)(2) { ["b"]=> object(test3)(1) { ["p"]=> *RECURSION* } ["counter"]=> int(2) } } ["counter"]=> int(2) } } ["counter"]=> int(3) } }