note 48376 deleted from language.functions by googleguy
| From: | googleguy@php.net | Date: | Mon, 24 Aug 2015 10:00:48 +0000 |
| Subject: | note 48376 deleted from language.functions by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203433@lists.php.net to get a copy of this message | ||
Note Submitter: spy-j at rainbowtroopers dot com
----
Take care when using parameters passed by reference to return new values in it:
<?PHP
function foo( &$refArray, ....) {
UNSET($refArray); //<-- fatal!!!
for (....) {
$refArray[] = ....
}//end for
}//end foo
?>
I tried to make sure the passed variable is empty so i can fill it up as an array. So i put the
UNSET. Unfortunately, this seems to cause a loss with the reference to the passed variable: the
filled array was NOT returned in the passed argument refArray!
I have found that replacing unset as follows seems to work correctly:
<?PHP
function bar( &$refArray, ....) {
if (!EMPTY($refArray)) $refArray = '';
: : :
}//end bar
?>