note 17322 deleted from language.references.return by sniper

From: Date: Tue, 30 Sep 2003 01:26:07 +0000
Subject: note 17322 deleted from language.references.return by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57352@lists.php.net to get a copy of this message
Note Submitter: phil@nospam.w30wnzj00.com ---- 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.

« previous php.notes (#57352) next »