In this tutorial we will see how to catch the fatal errors in PHP. Normally we can’t cache FATAL Error because those are FATAL.
This will be useful when you want to show specific well formatted error page rather than PHP Error, when your program ends unexpectedly due to some fatal errors.
We will use register_shutdown_function function to catch the fatal errors and format as we need.
Keep in mind that register_shutdown_function will gets executed after your script execution ends either it is successful or ends with any error.
So before performing any action in this function we need to check if really any fatal occurs or not. If occurs then we will show error page else it will continue to run as it is. So to get the details of the last error we will use error_get_last() function.
Avinash Zala currently working at a leading web development company as a Sr. PHP Web Developer. He is the founder of the Xpert Developer. He has completed B.E. in Information Technology. Born and brought up in Ahmedabad. He loves to code and coding is all about passion for him. Follow him on twitter at Avinash Zala & Xpert Developer.
View all posts by: Avinash