Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindplay-dk/053e5b3443145cd2ebb4 to your computer and use it in GitHub Desktop.
Save mindplay-dk/053e5b3443145cd2ebb4 to your computer and use it in GitHub Desktop.
Relay php errors to exceptions
<?php
/**
* Map php errors to the built-in ErrorException class.
*
* Respects the error_reporting() setting and the error-suppression operator.
*
* @see ErrorException
*/
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
$error = new ErrorException($errstr, 0, $errno, $errfile, $errline);
if ($error->getSeverity() & error_reporting()) {
throw $error;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment