Last active
January 4, 2016 12:59
-
-
Save texdc/8624676 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* 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