Like this answer , you can use register_shutdown_function() to register a callback that will check error_get_last() .
You still have to control the output generated due to code violation, regardless of the @ (shut up) operator, or ini_set('display_errors', false)
ini_set('display_errors', false); error_reporting(-1); set_error_handler(function($code, $string, $file, $line){ throw new ErrorException($string, null, $code, $file, $line); }); register_shutdown_function(function(){ $error = error_get_last(); if(null !== $error) { echo 'Caught at shutdown'; } }); try { while(true) { $data .= str_repeat('#', PHP_INT_MAX); } } catch(\Exception $exception) { echo 'Caught in try/catch'; }
At startup, the outputs are Caught at shutdown . Unfortunately, an ErrorException not ErrorException because a fatal error triggers the completion of the script, subsequently falling into the shutdown function only.
You can check the $error array in the shutdown function to get detailed information about the reason and respond accordingly. One sentence could re-send the request back to your web application (at a different address or with different parameters) and return the captured response.
I recommend keeping error_reporting() high (value -1 ) and using (as others suggested) error handling for everything else with set_error_handler() and ErrorException .
Dan Lugg Dec 09 '11 at 3:45 2011-12-09 03:45
source share