note 48125 added to language.oop5.basic
| From: | (php@tsg1985.com) | Date: | Mon, 13 Dec 2004 04:36:33 +0000 |
| Subject: | note 48125 added to language.oop5.basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81737@lists.php.net to get a copy of this message | ||
"Actually, the new variable will access a COPY of the instance and not the SAME instance. This
is shown by the example: var_dump($assigned) was not NULLified because a COPY of the instance was
assigned to $assigned..."
This is actually incorrect. However, it is explained really poorly in the article.
$instance = new SimpleClass();
This creates the new SimpleClass Object location in the memory. (This spot in memory stores all of
the variable and the code to execute.)Then, it points the variable $instance to that location in the
memory.
$assigned =$instance;
This takes the location that $instance is pointed to and points the variable $assigned to it as
well.
$reference =& $instance;
This line of code points $refrence to the memory spot which contains the location of the SimpleClass
object, not the object!
$instance->var = '$assigned will have this value';
This changes the values stored in SimpleClass Object's memory. Since $assigned points to this
location as well, $assinged>var is the same value.
$instance = null;
This tells instance to point at nothing. So, it breaks its link to the SimpleClass object. $refrence
points to $instance still, but since $instance points to nothing $refrence will also point to
nothing.
I know this is kind of tough to understand, so I made an animated gif showing the steps.
http://www.prism.gatech.edu/~gtg624r/Code_Explenation.gif
----
Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48125
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48125&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48125&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48125&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48125&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48125&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48125&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48125&report=yes
Search -- http://master.php.net/manage/user-notes.php