Easy Tutorial
❮ Func Ftp Quit Func Array Uksort ❯

PHP set_error_handler() Function



Definition and Usage

The set_error_handler() function sets a user-defined error handler function.

This function is used to create your own error handling method during runtime.

It returns the old error handler, or NULL on failure.

Syntax

Parameter Description
error_function Required. Specifies the function to run when an error occurs.
error_types Optional. Specifies which error report level(s) will trigger the user-defined error. Default is "E_ALL". See possible error report levels in the table below.

error_function

Syntax

Parameter Description
error_level Required. Specifies the error report level for the user-defined error. Must be a numeric value. See possible error report levels in the table below.
error_message Required. Specifies the error message for the user-defined error.
error_file Optional. Specifies the filename in which the error occurred.
error_line Optional. Specifies the line number at which the error occurred.
error_context Optional. Specifies an array pointing to the active symbol table at the point the error occurred. In other words, error_context will contain an array describing each variable that existed in the scope the error was triggered in.

Error Report Levels

Value Constant Description
2 E_WARNING Non-fatal run-time errors. Execution of the script is not halted.
8 E_NOTICE Run-time notices. The script found something that might be an error, but could also happen when running a script normally.
256 E_USER_ERROR Fatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error().
512 E_USER_WARNING Non-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error().
1024 E_USER_NOTICE User-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error().
4096 E_RECOVERABLE_ERROR Catchable fatal error. This is like an E_ERROR that can be caught by a user-defined handle (see set_error_handler()).
8191 E_ALL All errors and warnings, except of level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0).

Tips and Notes

Tip: When this function is used, it bypasses the standard PHP error handler entirely. If necessary, the user-defined error handler must terminate the script (using die()). Note: If an error occurs before the script is executed, the custom error handler cannot be used because it has not been registered at that point.


Example

The output of the above code is as follows:


❮ Func Ftp Quit Func Array Uksort ❯