|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-10-23 09:25 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue May 19 19:00:02 2026 UTC |
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 ...