Helping ordinary people create extraordinary websites!

Customizing the PHP Error Handler

By Tony Marston
2005-04-09

Introduction
One of the last areas that developers seem to deal with in their code is error handling. I am not talking here about errors with user input where it is a simple matter to display an error message and ask for new input, I am taking about the kind of error over which the user has absolutely no control and which may cause the current PHP script to stop running. In this situation you as a developer need to know some details about the error otherwise you will have a very difficult time in locating the source of the error so that you can fix it.

Developers new to PHP often complain there there is no proper error handling in the language. This is utter nonsense. All the functionality is there, you just have to customise it to your specific requirements.

In this tutorial I will show to how to create an error handler that will:

• Trap all errors whether triggered by PHP or a specific function call.
• Filter all errors depending on their error level.
• Output a formatted error message to the user.
• Send an email to the system administrator.
• Write the error details to a separate log file.




Tutorial pages:
 1 Votes

You might also want to check these out:


Leave a Comment on "Customizing the PHP Error Handler"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS