Created
August 4, 2021 11:22
-
-
Save devbanana/b31c85859c76a87e3670950d3315a17c to your computer and use it in GitHub Desktop.
In PHP 8, error_reporting() no longer returns 0 if error suppression is enabled using @. Here is how you detect if you should respond to an error in a custom error handler.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
set_error_handler(function (int $errno, string $errstr): bool { | |
if (!(error_reporting() & $errno)) { | |
// Do nothing | |
return false; | |
} | |
echo "Received error with message: $errstr\n"; | |
return true; | |
}); | |
@trigger_error('Oops', E_USER_WARNING); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment