Re: PHP 4.0 Bug #5408: foreach() should silently ignore non-array's passed to it
| From: | Stefan Livieratos | Date: | Wed, 05 Jul 2000 15:59:10 +0000 |
| Subject: | Re: PHP 4.0 Bug #5408: foreach() should silently ignore non-array's passed to it | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-23607@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: <danbeck@dealnews.com>
To: <php-dev@lists.php.net>
Sent: Thursday, July 06, 2000 5:35 PM
Subject: [PHP-DEV] PHP 4.0 Bug #5408: foreach() should silently ignore
non-array's passed to it
> From: danbeck@dealnews.com
> Operating system: Redhat 6.1 (Linux 2.2.12-20)
> PHP version: 4.0 Latest CVS (06/07/2000)
> PHP Bug Type: Feature/Change Request
> Bug description: foreach() should silently ignore non-array's passed to
it
>
> I feel foreach() should silently ingore any non-array variables passed to
it, especially if this was modeled after the same Perl statement. At the
very least, I would like to be able to use the @ notation in front of it so
that the script won't die if it doesn't get it's array.
foreach is a statement not a function so you can't use @.
> Otherwise, I have to continually use is_array() before using foreach()
just to make sure my script continues to live.
PHP scripts don't die when they encounter E_WARNINGs.
> Since PHP doesn't make you delcare or initialize variables, you can't
always expect that the variables you give a statement or function will be
what they are supposed to me.
Write yourself an error_handler which ignores foreach warnings:
---8<---
function error_handler($type, $msg) {
if($type==E_WARNING && ereg("foreach",$msg)) {
return;
} else {
print $msg;
}
}
set_error_handler("error_handler");
---8<---
Regards,
Stefan