How to handle error messages in PHP

Error messages are nightmares to a programmer. Default error messages are annoying and looking ugly. And kind of security threat as well. You probably wish to show a custom message when an error occurred. And tried and failed?

I had written this small code snippet for one of my projects and now wondering if this can help others. This function will triggered when a shutdown event happens.

Place this code at the top of your project file. Or maybe create a separate file and include where required.

This will help you handle messages for fatal error, undefined function error and required file not found error. And a general message for other errors.

So, when an undefined function is called, for example

It’ll show your defined message instead of showing-

You can change messages in line 27, 31, 35 and 39 with your own texts too.

Need help with your WordPress tasks?