#3462 [Analyzed->Won't fix]: foreach behavior on a non-array

From: Date: Sat, 27 Jul 2002 11:27:35 +0000
Subject: #3462 [Analyzed->Won't fix]: foreach behavior on a non-array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-15414@lists.php.net to get a copy of this message
 ID:               3462
 Updated by:       derick@php.net
 Reported By:      leon@leonatkinson.com
-Status:           Analyzed
+Status:           Won't fix
 Bug Type:         Feature/Change Request
 Operating System: all
 PHP Version:      4.0 Beta 3


Previous Comments:
------------------------------------------------------------------------

[2000-07-31 22:41:22] waldschrott@php.net

Why don´t you let your cache function return an empty array?
I think you should take care about passing foreach() the
right types...

Anyway PHPs handling of conversion unfortunately differs a
lot from function to function and statement to statement.
Thus I really don´t know what to do with this one I´ll mark
it analyzed.

------------------------------------------------------------------------

[2000-02-11 22:38:48] leon@leonatkinson.com

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.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=3462&edit=1



Thread (1 message)

  • derick@php.net
  • Unknown Message
    • derick@php.net
« previous php.bugs (#15414) next »