Skip to content

Instantly share code, notes, and snippets.

@devbanana
Created August 4, 2021 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devbanana/b31c85859c76a87e3670950d3315a17c to your computer and use it in GitHub Desktop.
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.
<?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