#19140 [NEW]: foreach fails on empty or uninitialized variable
| From: | jc at mega-bucks dot co dot jp | Date: | Wed, 28 Aug 2002 08:37:13 +0000 |
| Subject: | #19140 [NEW]: foreach fails on empty or uninitialized variable | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-18002@lists.php.net to get a copy of this message | ||
From: jc@mega-bucks.co.jp
Operating system: Red Hat Linux 7.2
PHP version: 4.2.2
PHP Bug Type: Arrays related
Bug description: foreach fails on empty or uninitialized variable
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 ...
--
Edit bug report at http://bugs.php.net/?id=19140&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=19140&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=19140&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=19140&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=19140&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=19140&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=19140&r=support
Expected behavior: http://bugs.php.net/fix.php?id=19140&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=19140&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=19140&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=19140&r=globals