note 17706 added to language.references
| From: | php-general at lists dot php dot net | Date: | Thu, 20 Dec 2001 15:46:02 +0000 |
| Subject: | note 17706 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-23361@lists.php.net to get a copy of this message | ||
Succesive assignement by reference and simple assignement :
$a = 'old';
$b = &$a;
$a = 'new';// now $b's value is new
$c = $b;// simple copy
$a = 'new new'; // $b is 'new new', $c is still 'new'
And now with arrays :
$a[0] = 'old';
$b = &$a;
$c = $b;//simple copy
$a[0] = 'new';// $b[0] is new, and $c[0] is still 'old'
BUT :
$a = 'old';
$b[0] = &$a;
$c = $b; // simple copy
$a = 'new';//now BOTH $b[0] and $c[0] are 'new'
A simple copying of an array (or an object) does NOT
break references for the values (or instance variables).
Use var_dump() to see which of the values in an array
are references.
Ivan
--
http://www.php.net/manual/en/language.references.php
http://master.php.net/manage/user-notes.php?action=edit+17706
http://master.php.net/manage/user-notes.php?action=delete+17706
http://master.php.net/manage/user-notes.php?action=reject+17706