Re: foreach fails on unitialized array?

From: Date: Fri, 30 Aug 2002 23:22:18 +0000
Subject: Re: foreach fails on unitialized array?
Groups: php.general 
Request: Send a blank email to php-general+get-114720@lists.php.net to get a copy of this message
>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 is the expected behaviour. If you absolute *MUST* refuse to initialize the array (BAD IDEA!) you could set error_reporting to (E_ALL - E_NOTICE) in php.ini or using http://php.net/error_reporting You would be *MUCH* better off listening to those warnings and fixing your code. *MUCH* better off. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#114720) next »