|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-02-10 11:00 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 10:00:01 2025 UTC |
Running the code below shows that $cls->tProperty is _NOT_ the same variable as the object itself. However, it should be. It lies that $cls->tProperty is another instance of tClass class. Despite of this, when one changes the name property, it will result in change in both objects, and that's correct. class tClass { var $tProperty; var $name; function tClass() { $this->tProperty =& $this; } }; echo "<pre>"; $cls =& new tClass(); $cls->name = "Sam"; print_r($cls); $cls->name = "George"; print_r($cls); echo "</pre>"; /* ---------------------------- Output: ---------------------------- tclass Object ( [tProperty] => tclass Object ( [tProperty] => *RECURSION* [name] => Sam ) [name] => Sam ) tclass Object ( [tProperty] => tclass Object ( [tProperty] => *RECURSION* [name] => George ) [name] => George ) ---------------------------- Instead of: ---------------------------- tclass Object ( [tProperty] => *RECURSION* [name] => Sam ) tclass Object ( [tProperty] => *RECURSION* [name] => George ) */