Home > PHP > Function > Error Handling > set_error_handler()

set_error_handler()

set_error_handler - Sets a user-defined error handler function

Syntax

set_error_handler (callback $error_handler, int $error_types, int $errno, string $errstr, string $errfile, int $errline, array $errcontext, callback $error_handler, int $error_types, int $errno, string $errstr, string $errfile, int $errline, array $errcontext)

Arguments

  • error_handler - The user function needs to accept two parameters: the error code, and a string describing the error. Then there are three optional parameters that may be supplied: the filename in which the error occurred, the line number in which the error occurred, and the context in which the error occurred (an array that points to the active symbol table at the point the error occurred). The function can be shown as: handler ( int , string [, string [, int [, array ]]]) errno The first parameter, errno, contains the level of the error raised, as an integer. errstr The second parameter, errstr, contains the error message, as a string. errfile The third parameter is optional, errfile, which contains the filename that the error was raised in, as a string. errline The fourth parameter is optional, errline, which contains the line number the error was raised at, as an integer. errcontext The fifth parameter is optional, errcontext, which is an array that points to the active symbol table at the point the error occurred. In other words, errcontext will contain an array of every variable that existed in the scope the error was triggered in. User error handler must not modify error context. If the function returns FALSE then the normal error handler continues.
  • error_types - Can be used to mask the triggering of the error_handler function just like the error_reportingini setting controls which errors are shown. Without this mask set the error_handler will be called for every error regardless to the setting of the error_reportingsetting.
  • errno
  • errstr
  • errfile
  • errline
  • errcontext
  • error_handler - The user function needs to accept two parameters: the error code, and a string describing the error. Then there are three optional parameters that may be supplied: the filename in which the error occurred, the line number in which the error occurred, and the context in which the error occurred (an array that points to the active symbol table at the point the error occurred). The function can be shown as: handler ( int , string [, string [, int [, array ]]]) errno The first parameter, errno, contains the level of the error raised, as an integer. errstr The second parameter, errstr, contains the error message, as a string. errfile The third parameter is optional, errfile, which contains the filename that the error was raised in, as a string. errline The fourth parameter is optional, errline, which contains the line number the error was raised at, as an integer. errcontext The fifth parameter is optional, errcontext, which is an array that points to the active symbol table at the point the error occurred. In other words, errcontext will contain an array of every variable that existed in the scope the error was triggered in. User error handler must not modify error context. If the function returns FALSE then the normal error handler continues.
  • error_types - Can be used to mask the triggering of the error_handler function just like the error_reportingini setting controls which errors are shown. Without this mask set the error_handler will be called for every error regardless to the setting of the error_reportingsetting.
  • errno
  • errstr
  • errfile
  • errline
  • errcontext

Description

Sets a user function ( error_handler) to handle errors in a script.

Version

PHP 4.0.1, 5

Return value

Returns a string containing the previously defined error handler (if any). If the built-in error handler is used NULL is returned. NULL is also returned in case of an error such as an invalid callback. If the previous error handler was a class method, this function will return an indexed array with the class and the method name.