|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-08-28 04:37 UTC] jc at mega-bucks dot co dot jp
The following code generates an error/warning:
$a = return_nothing();
foreach ($a as $val) {
echo "hi";
}
function return_nothing() {
}
OUTPUT:
Warning: Invalid argument supplied for foreach() in test.php on line 5
The documentation does not state what the correct/expected behaviour of foreach should be in the case of an unitialized array. It would be nice if foreach could recognize unitialized variables as being equivalent to "empty" arrays ...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
What is the documented/expected behaviour for foreach on "null" arrays? PHP has not problems with statements such as: echo "$a"; So I don't see why it should have a problem with: foreach ($a as $val) {}; Actaully I *do* understand why it is a problem :) I just would like it to suggest that foreach be able to handle null arrays. It would be *such* a nice feature ;)