note 92955 added to language.oop5.references
| From: | mjung at poczta dot onet dot pl | Date: | Sun, 16 Aug 2009 05:25:38 +0000 |
| Subject: | note 92955 added to language.oop5.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159540@lists.php.net to get a copy of this message | ||
Ultimate explanation to object references:
NOTE: wording 'points to' could be easily replaced with 'refers ' and is used
loosly.
<?php
$a1 = new A(1); // $a1 == handle1-1 to A(1)
$a2 = $a1; // $a2 == handle1-2 to A(1) - assigned by value (copy)
$a3 = &$a1; // $a3 points to $a1 (handle1-1)
$a3 = null; // makes $a1==null, $a3 (still) points to $a1, $a2 == handle1-2 (same object
instance A(1))
$a2 = null; // makes $a2 == null
$a1 = new A(2); //makes $a1 == handle2-1 to new object and $a3 (still) points to $a1 => handle2-1
(new object), so value of $a1 and $a3 is the new object and $a2 == null
//By reference:
$a4 = &new A(4); //$a4 points to handle4-1 to A(4)
$a5 = $a4; // $a5 == handle4-2 to A(4) (copy)
$a6 = &$a4; //$a6 points to (handle4-1), not to $a4 (reference to reference references the
referenced object handle4-1 not the reference itself)
$a4 = &new A(40); // $a4 points to handle40-1, $a5 == handle4-2 and $a6 still points to
handle4-1 to A(4)
$a6 = null; // sets handle4-1 to null; $a5 == handle4-2 = A(4); $a4 points to handle40-1; $a6
points to null
$a6 =&$a4; // $a6 points to handle40-1
$a7 = &$a6; //$a7 points to handle40-1
$a8 = &$a7; //$a8 points to handle40-1
$a5 = $a7; //$a5 == handle40-2 (copy)
$a6 = null; //makes handle40-1 null, all variables pointing to (hanlde40-1 ==null) are null, except
($a5 == handle40-2 = A(40))
?>
Hope this helps.
----
Server IP: 64.71.164.2
Probable Submitter: 24.131.165.243
----
Manual Page -- http://www.php.net/manual/en/language.oop5.references.php
Edit -- https://master.php.net/note/edit/92955
Del: integrated -- https://master.php.net/note/delete/92955/integrated
Del: useless -- https://master.php.net/note/delete/92955/useless
Del: bad code -- https://master.php.net/note/delete/92955/bad+code
Del: spam -- https://master.php.net/note/delete/92955/spam
Del: non-english -- https://master.php.net/note/delete/92955/non-english
Del: in docs -- https://master.php.net/note/delete/92955/in+docs
Del: other reasons-- https://master.php.net/note/delete/92955
Reject -- https://master.php.net/note/reject/92955
Search -- https://master.php.net/manage/user-notes.php