Try this code to catch all errors:
<?php $_caughtError = false; register_shutdown_function( // handle fatal errors function() { global $_caughtError; $error = error_get_last(); if( !$_caughtError && $error ) { throw new \ErrorException($error['message'], $error['type'], 2, $error['file'], $error['line']); } } ); set_error_handler( function($errno, $errstr, $errfile, $errline) { global $_caughtError; $_caughtError = true; throw new \ErrorException($errstr, $errno, 1, $errfile, $errline); } );
It must be executed or included before other code.
You can also implement Singleton to avoid global variables or let it throw two exceptions if you don't mind.
source share