ID: 43072 Updated by: [EMAIL PROTECTED] Reported By: php at bucksvsbytes dot com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Ubuntu PHP Version: 5.2.4 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Previous Comments: ------------------------------------------------------------------------ [2007-10-22 23:33:09] php at bucksvsbytes dot com Description: ------------ In PHP4, foreach($array) runs without error if $array is an uninitialized array. The foreach block is executed 0 times. This is consistent with other 0 iteration blocks such as while(false) and for($i=0;$i<0). In PHP5, an inconsistency was introduced by throwing an "invalid argument" warning when $array is an uninitialized array. In upgrading to PHP5 I had to add a surrounding if($array) block to hundreds of foreach blocks to eliminate the possible warning message. Reproduce code: --------------- unset($array);//just to clarify initial conditions foreach($array['phone'] as $key=>$phone){ echo $phone.'<br/>'; } Expected result: ---------------- I expect no errors and nothing echoed. This is PHP4 behavior. Actual result: -------------- In PHP5, following message pointlessly prints: Warning: Invalid argument supplied for foreach() in ... ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43072&edit=1
