note 43779 added to language.oop.newref
| From: | phpnotes at robertdhill dot com | Date: | Sat, 03 Jul 2004 04:29:58 +0000 |
| Subject: | note 43779 added to language.oop.newref | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72354@lists.php.net to get a copy of this message | ||
An earler note asked why the equal operator doesn't just make a reference, assuming that a
direct reference would always be desired.
The answer is because a direct reference is *not* always desired.
When you instantiate a class, you are creating an object that has its own copy of all the class
variables, access to the class methods, etc.
Now say you've created an instance of a class "MyClass" called "myObjectA"
and you've done some processing to it, set some variables or whatever. Now say you want to
create a duplicate of the object to do some changes, but you want to *keep the original.*
That is what the assignment (=) operator is for.
If you'd made a reference (&=), then any changes you make to the duplicate are also
reflected in the original. This is undesireable.
So there are circumstances where the assignment (=) operator is required, and there are
circumstances where the reference (&=) operator is required.
It just depends on what you're doing.
Hope this helps.
----
Manual Page -- http://www.php.net/manual/en/language.oop.newref.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43779
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43779&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43779&report=yes
Search -- http://master.php.net/manage/user-notes.php