Edit report at https://bugs.php.net/bug.php?id=6118&edit=1

 ID:                 6118
 Comment by:         sanibelmatt7 at aol dot com
 Reported by:        ronen at greyzone dot com
 Summary:            Can not supress runtime warnings on foreach using @
                     operator
 Status:             Open
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        *
 Block user comment: N
 Private report:     N

 New Comment:

with $x of course being the returned array of a query


Previous Comments:
------------------------------------------------------------------------
[2012-02-23 00:29:50] sanibelmatt7 at aol dot com

just as 'slight_ at hotmail dot com ' had put it, they best way to get rid of 
it is a simple if/else loop, say 

 if(!$x) {
echo "error" 
} 
else {
//code//
}
it worked on my the website i am developing so hopefully it'll work for you

------------------------------------------------------------------------
[2008-03-04 23:10:15] slight_ at hotmail dot com

I'd just like to add a vote for this as a new feature. I have countless foreach 
blocks wrapped in if( is_array( $x ) ){} where the only reason to check is to 
avoid raising a warning.

------------------------------------------------------------------------
[2000-08-12 03:12:31] s...@php.net

Well, it's still a valid feature request. Why to be overzealous to close it, 
maybe somewhere in PHP 6.5 we decide to implement it? :)

------------------------------------------------------------------------
[2000-08-12 03:01:58] sterl...@php.net

Actually its not that...
   foreach is a statement, you can't suppress warnings for statements.

------------------------------------------------------------------------
[2000-08-12 02:40:05] der...@php.net

At the moment it seems that parse errors can not be suppressed, but I think it 
is not possible to do it, and it is absolutely not useful.

>From the manual:
"All PHP expressions can also be called with the "@" prefix, which turns off 
error reporting for that particular expression"

But if PHP can see there is an expression (because of an parse error), there is 
no way to disable warnings from that statement.

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=6118


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

Reply via email to