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.

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.

error_reportingintegerSet the error reporting level.NULLPHP_INI_ALL
display_errorsstringDetermines if errors are displayed or hidden.“1” PHP_INI_ALL
display_startup_errorsbooleanEven if display_errors is on, hides errors that occur during PHP’s startup sequence. Keep it off when online.“0”PHP_INI_ALL
log_errorsbooleanSpecifies if script error messages should be logged to the server’s error log.“0”PHP_INI_ALL
log_errors_max_lenintegerSpecifies the maximum length of log_errors in bytes.“1024”PHP_INI_ALL
ignore_repeated_errors booleanDo not log repeated messages.“0”PHP_INI_ALL
ignore_repeated_sourcebooleanIgnore source of message when ignoring repeated messages.“0”PHP_INI_ALL
report_memleaksbooleanIf set to Off, memory leaks (the program is unable to release memory it has occupied) will not be displayed.“1”PHP_INI_ALL
track_errorsbooleanIf enabled, variable $php_errormsg will always hold the last error message.“0”PHP_INI_ALL
html_errorsbooleanTurns HTML tags off in error messages.“1” PHP_INI_ALL
xmlrpc_errorsbooleanFormats errors as XML-RPC error message, turning normal error reporting off.“0”PHP_INI_SYSTEM
xmlrpc_error_numberintegerUsed as the value of the XML-RPC fault Code element.“0”PHP_INI_ALL
docref_rootstringFormat of a new error which contains a reference to a page describing the error or function causing the error.“”PHP_INI_ALL
docref_extstringSpecifies the file extension of the reference page (as mentioned in docref_root).“”PHP_INI_ALL
error_prepend_stringstringString to output before an error message.NULLPHP_INI_ALL
error_append_stringstringString to output after an error message.NULLPHP_INI_ALL
error_logstringName of the file where script errors should be logged.NULLPHP_INI_ALL

PHP error handling – predefined constants

DescriptionList 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 : 

E_ERRORintegerExecution of the script comes to a halt. An example is memory allocation problem.1
E_WARNINGintegerExecution of the script is not halted, warnings generated. 2
E_PARSE integerParse errors generated by parsers during compilation.4
E_NOTICE integerRun-time notices which indicated that may be an error took place but may also be a normal course of action.8
E_CORE_ERRORintegerFatal errors that occur during the initial startup of PHP.16
E_CORE_WARNINGintegerWarnings (execution of the script is not halted) that occur during PHP’s initial startup.32
E_COMPILE_ERROR  integerFatal compile-time errors.64
E_COMPILE_WARNING  integerCompile-time warnings, execution of the script is not halted.128
E_USER_ERROR  integerUser-generated error message. 256
E_USER_WARNINGintegerUser-generated warning message. 512
E_USER_NOTICEintegerSame as E_NOTICE. The only difference is, trigger_error() function is used here to generate the error message.1024 
E_STRICTinteger User-generated notice message.2048
E_RECOVERABLE_ERROR integerCatchable fatal error.4096
E_DEPRECATED integerRun-time notices. 8192
E_USER_DEPRECATED integerUser-generated warning message.16384
E_ALL integerAll errors and warnings, as supported. Exception level E_STRICT.30719

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

Follow Us On