note 48125 deleted from language.oop5.basic by colder

From: Date: Sun, 19 Aug 2007 23:39:22 +0000
Subject: note 48125 deleted from language.oop5.basic by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-129608@lists.php.net to get a copy of this message
Note Submitter: Richard (php at tsg1985 dot com) ---- "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

« previous php.notes (#129608) next »