Easy Tutorial
❮ Func String Strlen Func Math Sin ❯

PHP Error and Logging Functions


PHP Error and Logging Introduction

Error and Logging functions allow you to handle and log errors.

Error functions enable users to define error handling rules and modify how errors are logged.

Logging functions allow users to log application activities and send log messages to emails, system logs, or other machines.


Execution Configuration

Error functions are influenced by the php.ini configuration file.

Error and Logging Configuration Options:

Parameter Default Value Description Changeable Scope
error_reporting NULL Sets the error reporting level and returns the current level (numeric or constant). PHP_INI_ALL
display_errors "1" Determines whether error messages should be part of the output or hidden from the user. <br> Note: Do not use this feature in a production environment (use in development and testing). PHP_INI_ALL
display_startup_errors "0" Startup errors are not displayed even if display_errors is enabled. It is strongly recommended to keep display_startup_errors disabled except for debugging purposes. PHP_INI_ALL
log_errors "0" Sets whether to log script error messages to the server error log or to error_log. Note, this is server-specific configuration. PHP_INI_ALL
log_errors_max_len "1024" Sets the maximum byte length for log_errors. Information about the error origin is added to the error_log. The default is 1024, and setting it to 0 means unlimited length. This length affects logged errors, displayed errors, and $php_errormsg. PHP_INI_ALL
ignore_repeated_errors "0" Does not log repeated messages. Repeated errors must occur in the same file and the same line unless ignore_repeated_source is set to true. PHP_INI_ALL
ignore_repeated_source "0" Ignores the source of the message when ignoring repeated messages. When enabled, repeated messages will not log whether they come from different files or source lines. PHP_INI_ALL
report_memleaks "1" If set to Off, memory leak information will not be shown (in stdout or logs). PHP_INI_ALL
track_errors "0" If enabled, the last error will always be present in the variable $php_errormsg. PHP_INI_ALL
html_errors "1" Turns off HTML tags in error messages. PHP_INI_ALL <br>PHP_INI_SYSTEM in PHP <= 4.2.3.
xmlrpc_errors "0" Turns off normal error reporting and formats errors as XML-RPC error messages. PHP_INI_SYSTEM
xmlrpc_error_number "0" Used as the value for the XML-RPC faultCode element. PHP_INI_ALL
docref_root "" The new error message format includes a reference page that describes the error in detail or the function that caused it. <br>To provide manual pages, you can download the corresponding language manual from the PHP official site and set the URL to the local address in the ini file. <br>If your local manual copy can be accessed with "/manual/", you can simply set docref_root=/manual/. <br>You also need to set docref_ext to match the local file suffix, like docref_ext=.html. It's also possible to set an external reference address. <br>For example, you can set docref_root=http://manual/en/ or docref_root="http://landonize.it/?how=url&theme=classic&filter=Landon &url=http%3A%2F%2Fwww.php.net%2F" PHP_INI_ALL
docref_ext "" See docref_root. PHP_INI_ALL
error_prepend_string NULL Content to output before the error message. PHP_INI_ALL
error_append_string NULL Content to output after an error message. PHP_INI_ALL
error_log NULL Sets the file where script errors should be logged. The file must be writable by the web server user. PHP_INI_ALL

Installation

Error and Logging functions are part of the PHP core. No installation is required to use these functions.


PHP Error and Logging Functions

PHP: Indicates the earliest PHP version that supports the function.

Function Description PHP
debug_backtrace() Generates a backtrace. 4
debug_print_backtrace() Prints a backtrace. 5
error_get_last() Gets the last occurred error. 5
error_log() Sends an error to the server's error log, a file, or a remote destination. 4
error_reporting() Specifies which errors are reported. 4
restore_error_handler() Restores the previous error handler. 4
restore_exception_handler() Restores the previous exception handler. 5
set_error_handler() Sets a user-defined error handler function. 4
set_exception_handler() Sets a user-defined exception handler function. 5
trigger_error() Creates a user-defined error message. 4
user_error() Alias of trigger_error(). 4

PHP Error and Logging Constants

PHP: Indicates the earliest PHP version that supports the constant.

Value Constant Description PHP
1 E_ERROR Fatal run-time errors. These indicate errors that cannot be recovered from. Execution of the script is halted.
2 E_WARNING Non-fatal run-time errors. Execution of the script is not halted.
4 E_PARSE Compile-time parse errors. Parse errors should only be generated by the parser.
8 E_NOTICE Run-time notices. Indicates that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
16 E_CORE_ERROR Fatal errors that occur during PHP's initial startup. This is like an E_ERROR in the PHP core. 4
32 E_CORE_WARNING Non-fatal errors that occur during PHP's initial startup. This is like an E_WARNING in the PHP core. 4
64 E_COMPILE_ERROR Fatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine. 4
128 E_COMPILE_WARNING Non-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine. 4
256 E_USER_ERROR User-generated error message. This is like an E_ERROR set by the programmer using the PHP function trigger_error(). 4
512 E_USER_WARNING User-generated warning message. This is like an E_WARNING set by the programmer using the PHP function trigger_error(). 4
1024 E_USER_NOTICE User-generated notice message. This is like an E_NOTICE set by the programmer using the PHP function trigger_error(). 4
2048 E_STRICT Runtime notices. PHP suggests you to change your code to enhance interoperability and compatibility. 5
4096 E_RECOVERABLE_ERROR Catchable fatal error. This is akin to an E_ERROR that can be caught by a user-defined handler (see set_error_handler()). 5
6143 E_ALL All error and warning levels, except E_STRICT (from PHP 6.0 onwards, E_STRICT will be included as part of E_ALL). 5
❮ Func String Strlen Func Math Sin ❯