note 51353 added to language.functions

From: Date: Mon, 28 Mar 2005 17:36:33 +0000
Subject: note 51353 added to language.functions
Groups: php.notes 
Request: Send a blank email to php-notes+get-87096@lists.php.net to get a copy of this message
Note that a function that calls a variable by reference CANNOT be used recursively, it will generate a CGI error (at least on my windows platform). Thus: <?php $foo = 0; function bar(&$foo){ $foo++; echo $foo."\n"; if($foo < 10) bar($foo); } ?> Will NOT work. Instead, you should just use global variables. <?php $foo = 0; function bar(){ global $foo; $foo++; echo $foo."\n"; if($foo < 10) bar($foo); } ?> This, of course, assuming that you need to use $foo in other functions or parts of code. Otherwise you can simply pass the variable regulary and there should be no problems. ---- Manual Page -- http://www.php.net/manual/en/language.functions.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51353 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51353&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51353&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51353&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51353&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51353&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51353&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87096) next »