When I go to one of my php pages, I receive a bunch of errors. Some are a few warnings and one of which is a fatal error.
I was trying to find out if my page has any fatal errors. Is there a way to get a list of errors occurred on that page, so I can determine if a fatal error exists?
The function error_get_last() doesn't solve my purpose because it lists only the last occurred error and that might not necessarily be a fatal error.
Thanks,
I don't see what could be the use case for this, but to answer your question- you could set your own error handler, and catch all errors:
$errors = array();
set_error_handler(function($code, $msg, $file, $line, $context) use(&$errors){
$errors[] = compact('code', 'msg', 'file', 'line', 'context');
});
And check that array at the end of the script.
To "catch" fatal errors check for error_get_last()
during shutdown:
register_shutdown_function(function(){
$error = error_get_last();
if($error && in_array($error['type'], array(E_ERROR, E_PARSE, E_COMPILE_ERROR)){
// some kind of fatal error
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.