PHP Error Handling – Part Two, Standard Error Handling

This is a short post continuing the topic of errors in PHP, following on from error types & exceptions and leading to custom error handling, this post is a quick summary of the standard error reporting provided by PHP.

In my previous post I went over the myriad of error types in PHP as well as the basic exception throwing / catching mechanism, the code from that post with examples of all of the error types can be used to test that the functions and settings from this post and the next in fact work as expected in conjunction with these different types of errors.

Just a few things to know here:

The display_errors directive

To echo or not to echo, and the types of errors shown (or not shown) are determined by the next setting…

The error_reporting directive

This is where all of the error types previously discussed come into play as you can fine tune the types of errors reported using bitwise operators to combine the error constants. Prior to PHP 5.4 E_ALL did not include E_STRICT, so to ensure everything is reported, you would need to include it using the bitwise OR operator as in my example above.

The log_errors directive

Sets error logging of the error types chosen with error_reporting to the system log file.

The error_log directive

This sets the system log file location, by default this is empty in which case the errors will be logged to your Apache logs (or relevant SAPI error logger).

The error_log function

This simple function allows you to manually log a message to the error log as specified by the error_log directive, or to a custom location or even email with modifiers.


Not to complicated. Typically these settings are used in combination to show all errors during development or to log and not show errors in production. Remember that setting a custom error handler (as in the next post) will override these settings allowing your custom functionality to take over.


About Ingmar Boddington

Codemonkey, Sheffield, UK
This entry was posted in PHP and tagged Error Handling, PHP. Bookmark the permalink.