note 20942 added to language.references
| From: | php-general at lists dot php dot net | Date: | Mon, 22 Apr 2002 22:07:27 +0000 |
| Subject: | note 20942 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29702@lists.php.net to get a copy of this message | ||
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?)
--
http://www.php.net/manual/en/language.references.php
http://master.php.net/manage/user-notes.php?action=edit+20942
http://master.php.net/manage/user-notes.php?action=delete+20942
http://master.php.net/manage/user-notes.php?action=reject+20942