note 20942 deleted from language.references by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 01:18:12 +0000 |
| Subject: | note 20942 deleted from language.references by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57309@lists.php.net to get a copy of this message | ||
Note Submitter:
----
When you do
$a = new A();
PHP creates an object for you, and returns a COPY of that object
So (if I get it right... ) the child is actually altering the original object and not the copy that
you stored in $a.
However if you do
$a =& new A();
PHP still creates an object, but returns a REFERENCE to that object.
The child is still altering the original - but you are happy, because you have got a reference the
original!
so if you change the line
$a = new A();
to
$a =& new A();
you'll get the result you expected.
(BTW wouldn't it be more correct to say that when you do:
$a = new A()
PHP returns not a copy but a reference to a copy?)