PHP error handling


PHP has a number of functions for handling as well as reporting errors. Besides, you can define your own way of handling and reporting errors. In this and subsequent pages we are going to discuss installation, runtime configuration, predefined constants and functions relating to PHP error handling and reporting.

Installation and configuration

In PHP 5, you don't need any external library, and you don't need any installation in addition to error handling and reporting.

Configuration settings for PHP Error handling and reporting are available in php.ini file, which is located in the php installation folder of your system.
Following is a list of error handling settings, there descriptions, default value and where they can be changed (Changeable).

For reference, settings of any PHP configuration can be changed in various ways - using ini_set(), in WINDOWS registry, in php.ini, in .htaccess or in httpd.conf. PHP_INI_ALL refers that the related configuration can be changed in any the aforementioned ways. PHP_INI_SYSTEM refers the entry can be set in php.ini or httpd.conf.

Name Type Description Default Changeable
error_reporting integer Set the error reporting level. NULL PHP_INI_ALL
display_errors string Determines if errors are displayed or hidden. "1"  PHP_INI_ALL
display_startup_errors boolean Even if display_errors is on, hides errors that occur during PHP's startup sequence. Keep it off when online. "0" PHP_INI_ALL
log_errors boolean Specifies if script error messages should be logged to the server's error log. "0" PHP_INI_ALL
log_errors_max_len integer Specifies the maximum length of log_errors in bytes. "1024" PHP_INI_ALL
ignore_repeated_errors  boolean Do not log repeated messages. "0" PHP_INI_ALL
ignore_repeated_source boolean Ignore source of message when ignoring repeated messages. "0" PHP_INI_ALL
report_memleaks boolean If set to Off, memory leaks (the program is unable to release memory it has occupied) will not be displayed. "1" PHP_INI_ALL
track_errors boolean If enabled, variable $php_errormsg will always hold the last error message. "0" PHP_INI_ALL
html_errors boolean Turns HTML tags off in error messages. "1"  PHP_INI_ALL
xmlrpc_errors boolean Formats errors as XML-RPC error message, turning normal error reporting off. "0" PHP_INI_SYSTEM
xmlrpc_error_number integer Used as the value of the XML-RPC fault Code element. "0" PHP_INI_ALL
docref_root string Format of a new error which contains a reference to a page describing the error or function causing the error. "" PHP_INI_ALL
docref_ext string Specifies the file extension of the reference page (as mentioned in docref_root). "" PHP_INI_ALL
error_prepend_string string String to output before an error message. NULL PHP_INI_ALL
error_append_string string String to output after an error message. NULL PHP_INI_ALL
error_log string Name of the file where script errors should be logged. NULL PHP_INI_ALL

PHP error handling - predefined constants


List of predefined constants used in PHP 5 for error handling.

Predefined constants

Here is a list of the predefined constants used in PHP 5 for error handling : 

Name Type Description value
E_ERROR integer Execution of the script comes to a halt. An example is memory allocation problem. 1
E_WARNING integer Execution of the script is not halted, warnings generated.  2
E_PARSE  integer Parse errors generated by parsers during compilation. 4
E_NOTICE  integer Run-time notices which indicated that may be an error took place but may also be a normal course of action. 8
E_CORE_ERROR integer Fatal errors that occur during the initial startup of PHP. 16
E_CORE_WARNING integer Warnings (execution of the script is not halted) that occur during PHP's initial startup. 32
E_COMPILE_ERROR   integer Fatal compile-time errors. 64
E_COMPILE_WARNING   integer Compile-time warnings, execution of the script is not halted. 128
E_USER_ERROR   integer User-generated error message.  256
E_USER_WARNING integer User-generated warning message.  512
E_USER_NOTICE integer Same as E_NOTICE. The only difference is, trigger_error() function is used here to generate the error message. 1024 
E_STRICT integer  User-generated notice message. 2048
E_RECOVERABLE_ERROR  integer Catchable fatal error. 4096
E_DEPRECATED  integer Run-time notices.  8192
E_USER_DEPRECATED  integer User-generated warning message. 16384
E_ALL  integer All errors and warnings, as supported. Exception level E_STRICT. 30719

All these constants are available in  php.ini of your PHP installation folder.

Previous: XForms
Next: using-die()

Follow us on Facebook and Twitter for latest update.