Skip to content

Instantly share code, notes, and snippets.

@texdc
Last active January 4, 2016 12:59
Show Gist options
  • Save texdc/8624676 to your computer and use it in GitHub Desktop.
Save texdc/8624676 to your computer and use it in GitHub Desktop.
Custom Error Handler
<?php
/**
* Custom error handler
*
* @see http://www.php.net/manual/en/class.errorexception.php#95415
*/
set_error_handler(function ($number, $string, $file, $line) {
// Determine if this error is enabled (php.ini, .htaccess, etc)
if (!(error_reporting() & $number)) {
return true;
}
// -- FATAL ERROR
if (in_array($number, [E_USER_ERROR, E_RECOVERABLE_ERROR])) {
throw new ErrorException($string, 0, $number, $file, $line);
}
// -- NON-FATAL ERROR/WARNING/NOTICE
error_log($string, 0);
// Make sure this ends up in $php_errormsg, if appropriate
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment