#19140 [Opn->Bgs]: foreach fails on empty or uninitialized variable
| From: | cynic@php.net | Date: | Wed, 28 Aug 2002 08:41:31 +0000 |
| Subject: | #19140 [Opn->Bgs]: foreach fails on empty or uninitialized variable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-18004@lists.php.net to get a copy of this message | ||
ID: 19140
Updated by: cynic@php.net
Reported By: jc@mega-bucks.co.jp
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Red Hat Linux 7.2
PHP Version: 4.2.2
New Comment:
"an uninitialized array"? i don't see anything like that in your
example.
there's just one nonexistent (null, if you must) variable. no array.
Previous Comments:
------------------------------------------------------------------------
[2002-08-28 04:37:12] jc@mega-bucks.co.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 ...
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=19140&edit=1