note 48369 deleted from language.functions by tularis
| From: | tularis@php.net | Date: | Tue, 21 Dec 2004 09:22:36 +0000 |
| Subject: | note 48369 deleted from language.functions by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-82113@lists.php.net to get a copy of this message | ||
Note Submitter: spyj 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
?>
----
Reason: useless example