note 125938 added to language.operators.errorcontrol
| From: | RyanC@php.net | Date: | Wed, 17 Mar 2021 14:37:19 +0000 |
| Subject: | note 125938 added to language.operators.errorcontrol | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219145@lists.php.net to get a copy of this message | ||
It's still possible to detect when the @ operator is being used in the error handler in PHP8.
Calling error_reporting() will no longer return 0 as documented, but using the @ operator does still
change the return value when you call error_reporting().
My PHP error settings are set to use E_ALL, and when I call error_reporting() from the error handler
of a non-suppressed error, it returns E_ALL as expected.
But when an error occurs on an expression where I tried to suppress the error with the @ operator,
it returns: E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR
(or the number 4437).
I didn't want to use 4437 in my code in case it changes with different settings or future
versions of PHP, so I now use:
<?php
function my_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != E_ALL) {
return false; // Silenced
}
// ...
}
?>
If the code needs to work with all versions of PHP, you could check that error_reporting()
doesn't equal E_ALL or 0.
And, of course, if your error_reporting settings in PHP is something other than E_ALL, you'll
have to change that to whatever setting you do use.
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.246 (proxied: 2601:601:e03:ed0:d929:bf9a:4221:cf4f)
----
Manual Page -- http://php.net/manual/en/language.operators.errorcontrol.php
Edit -- https://master.php.net/note/edit/125938
Del: integrated -- https://master.php.net/note/delete/125938/integrated
Del: useless -- https://master.php.net/note/delete/125938/useless
Del: bad code -- https://master.php.net/note/delete/125938/bad+code
Del: spam -- https://master.php.net/note/delete/125938/spam
Del: non-english -- https://master.php.net/note/delete/125938/non-english
Del: in docs -- https://master.php.net/note/delete/125938/in+docs
Del: other reasons-- https://master.php.net/note/delete/125938
Reject -- https://master.php.net/note/reject/125938
Search -- https://master.php.net/manage/user-notes.php