The error_get_last() is an inbuilt function of PHP and is used to return the last error that occurred in your program. Returns an associative array describing the last error with keys: type, message, file, and line. Returns NULL if no error has occurred yet.
Example #1
1 2 3 4 |
<?php echo $test; print_r(error_get_last()); ?> |
Example #2
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php register_shutdown_function('handleFatalPhpError'); function handleFatalPhpError() { $last_error = error_get_last(); if($last_error['type'] === E_ERROR) { echo "Can do custom output and/or logging for fatal error here..."; } } ?> |
Example #3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php class Error{ function __construct(){ error_reporting ( E_ALL ^ E_NOTICE ); $err = error_get_last (); if($err){ $res = "An error has occurred in your application sir.\n Details Include " .$err."" } } } ?> |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.