note 77022 deleted from language.oop5.basic by danbrown
| From: | danbrown@php.net | Date: | Thu, 08 Apr 2010 19:29:13 +0000 |
| Subject: | note 77022 deleted from language.oop5.basic by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168043@lists.php.net to get a copy of this message | ||
Note Submitter: mep_eisen at web dot de
----
referring to steven's post:
****
Perhaps this is because =& statements join the 2 variable names in the symbol table, whereas =
statements applied to objects simply create a new independent entry in the symbol table that simply
points to the same location as other entries. I don't know for sure - I don't think this
behavior is documented in the PHP manual, so perhaps somebody with more knowledge of PHP's
internals can clarify what is going on.
****
lets talk about
a =& b;
b = c;
PHP internally marks a to be a reference to b. If You reassign b PHP does not update a. But if you
access a once more PHP looks at the current value of b (now containing c).
Both statements (a=b and a=&b) seem to do the same but they don't. However this changed for
objects from PHP4 to PHP5. Where PHP4 needed this operator to avoid object cloning, PHP5 does not
need it.
It is explained in chapter 21 (References Explained). It's important to understand that a
becomes a reference and the following code will not modify b:
a =& b;
a =& c;