PHP 5.2.0 bring us a new function : error_get_last()
It return an associative array describing the last error with keys “type”, “message”, “file” and “line” about the last error that occurred.
We can now use it with register_shutdown_function to handle fatal error, log, redirect, html page, instead of the infamous white page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/** * Handling fatal error * * @return void */ function fatalErrorHandler() { # Getting last error $error = error_get_last(); # Checking if last error is a fatal error if(($error['type'] === E_ERROR) || ($error['type'] === E_USER_ERROR)) { # Here we handle the error, displaying HTML, logging, ... echo 'Sorry, a serious error has occured in ' . $error['file']; } } # Registering shutdown function register_shutdown_function('fatalErrorHandler'); |
Resources :
- http://www.php.net/manual/en/function.error-get-last.php
- http://php.net/manual/en/errorfunc.constants.php
Awesome information!!! thanks