PHP 4.0 Bug #3462: foreach behavior on a non-array
| From: | leon at leonatkinson dot com | Date: | Fri, 11 Feb 2000 21:38:48 +0000 |
| Subject: | PHP 4.0 Bug #3462: foreach behavior on a non-array | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-15398@lists.php.net to get a copy of this message | ||
From: leon@leonatkinson.com
Operating system: all
PHP version: 4.0 Beta 3
PHP Bug Type: Feature/Change Request
Bug description: foreach behavior on a non-array
Given the following code:
unset($list);
foreach($list as $value)
{
print($value);
}
and $list is FALSE, PHP is generating an error like
"Non array argument supplied for foreach()". The
variable probably should be promoted to being an
empty array, but I can deal with casting it myself.
Unfortunately, when I do this:
unset($list);
foreach((array)$list as $value)
{
print($value);
}
it runs through the loop once. I know I can get around
this using a while loop, but I'd prefer to use foreach.
If anyone's wondering why the hell I'm looping over an
unset variable, I have a caching function that returns
the contents of a database table. When there are no
rows, it returns the unset static variable.