note 48376 added to language.functions

From: Date: Tue, 21 Dec 2004 11:01:45 +0000
Subject: note 48376 added to language.functions
Groups: php.notes 
Request: Send a blank email to php-notes+get-82123@lists.php.net to get a copy of this message
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 ?> ---- Manual Page -- http://www.php.net/manual/en/language.functions.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48376 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48376&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48376&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48376&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48376&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48376&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48376&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48376&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82123) next »