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:

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


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[2000-08-12 02:29:39] ronen at greyzone dot com

@foreach($items as $key => $val) {}

does not work:

<?
$test[123]="one hundred twenty three";
$test[13]="thirteen";
$test[11]="eleven";


// try to supress warnings on foreach
@foreach($test as $key => $value) {
        echo "TEST[$key]=$value<br>";
}

/***** THE OUTPUT IS


Parse error: parse error in /home/httpd/brocadedocs/ronen/secure/testtest.html 
on line 10
****/

?>


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



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

Reply via email to