|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-06-09 05:43 UTC] zeev at cvs dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 20:00:01 2025 UTC |
class class1 { var $class2; var $foo = 'bar'; function class1 () { $this->class2 = new class2 ($this); } function &get_ref_to_class2 () { return $this->class2; } } class class2 { var $ref_to_class1; function class2(&$ref_to_class1) { $this->ref_to_class1 = &$ref_to_class1; } } eval("\$c1 = new class1;"); /* here it is important, that this assignment is *not * done in the main_op_array, but (for example) in an eval op_array or in an op_array of a function, like the following (otherwise, the bug won't appear): function make_c1 () { global $c1; $c1 = new class1; } make_c1(); */ /* so now, let's test the stuff */ if(isset($c1->class2->ref_to_class1)) echo "isset(\$c1->class2->ref_to_class1) is TURE\n"; else echo "isset(\$c1->class2->ref_to_class1) is FALSE\n"; echo "\$c1->class2->ref_to_class1->foo is "; echo $c1->class2->ref_to_class1->foo, "\n<hr>"; /* everything should be ok so far */ $c2 = &$c1->get_ref_to_class2(); /* critical ... this seems to `destroy' ref_to_class1 */ /* the same tests again */ if(isset($c1->class2->ref_to_class1)) echo "isset(\$c1->class2->ref_to_class1) is TURE\n"; else echo "isset(\$c1->class2->ref_to_class1) is FALSE\n"; echo "\$c1->class2->ref_to_class1->foo is "; echo $c1->class2->ref_to_class1->foo, "\n<hr>"; /* fails !!!! */ /* it doesn't matter if one accesses ref_to_class1 through $c1 or $c2, it hasn't a valid type any more */ if(isset($c2->ref_to_class1)) echo "isset(\$c2->ref_to_class1) is TURE\n"; else echo "isset(\$c2->ref_to_class1) is FALSE\n"; /* ref_to_class1 is set, but of unknown type */ echo "gettype(\$c2->ref_to_class1): ", gettype($c2->ref_to_class1), "\n";