note 17322 added to language.references.return
| From: | phil at nospam dot w30wnzj00 dot com | Date: | Tue, 04 Dec 2001 15:58:09 +0000 |
| Subject: | note 17322 added to language.references.return | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21605@lists.php.net to get a copy of this message | ||
this is something about references that threw me off, maybe it'll help others too.
when returning references to parameters of a function such as:
function &reftest($array)
{
return $array[2];
}
$a = array(1,2,3);
$b = &reftest($a);
$b = 44;
this will not have the desired effect. $b is now a reference to the copy of the array in the
reftest() scope.
instead, be sure to pass the parameter as reference also, as in:
function &reftest(&$array)
{
return $array[2];
}
$a = array(1,2,3);
$b = &reftest($a);
$b = 44;
this has the expected effect as $b is now a reference to the original array.
--
http://www.php.net/manual/en/language.references.return.php
http://master.php.net/manage/user-notes.php?action=edit+17322
http://master.php.net/manage/user-notes.php?action=delete+17322
http://master.php.net/manage/user-notes.php?action=reject+17322