Re: [PHP] foreach fails on unitialized array?

2002-08-29 Thread Eric Pignot

I would expect foreach to treat an unitialized variable as an empty
array and hence do nothing. Is this the expected behaviour?

if(is_array($myvar)) foreach($myvar as $key = $value ) {
  ...
}

other possibility, so that the foreach is run each time (and it doesn't
affect the source code, you can put it wherever you want) :
if(!is_array($myvar)) {
$myvar = array();
}

regards !

Eric




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] foreach fails on unitialized array?

2002-08-27 Thread Jean-Christian Imbeault

When I use foreach on a uninitialized array I get the following warning:

Warning:  Invalid argument supplied for foreach() in 
/www/htdocs/jc/cart/add_item.php on line 21

I would expect foreach to treat an unitialized variable as an empty 
array and hence do nothing. Is this the expected behaviour?

Thanks,

Jc


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] foreach fails on unitialized array?

2002-08-27 Thread Michael Sims

On Wed, 28 Aug 2002 12:53:45 +0900, you wrote:

When I use foreach on a uninitialized array I get the following warning:

Warning:  Invalid argument supplied for foreach() in 
/www/htdocs/jc/cart/add_item.php on line 21

I would expect foreach to treat an unitialized variable as an empty 
array and hence do nothing. Is this the expected behaviour?

It's always been my experience.  I just get in a habit of doing this:

if(is_array($myvar)) foreach($myvar as $key = $value ) {
  ...
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php