set_error_handler

FunctionParams changed in PHP 8.0

Sets a user-defined error handler function.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2
PHP 8.3
PHP 8.4
PHP 8.5

set_error_handler Function synopsis

set_error_handler(?callable $callback, int $error_levels = E_ALL)

Parameters

$callback

Type?callable

If null is passed, the handler is reset to its default state. Otherwise, the handler is a callback with the following signature:

$error_levels

OptionalTypeintDefault valueE_ALL

Can be used to mask the triggering of the $callback function just like the error_reportingini setting controls which errors are shown. Without this mask set the $callback will be called for every error regardless to the setting of the error_reportingsetting.

Changes to the set_error_handler Function

PHP 8.0

  • Parameter name of parameter #1 changed: $error_handler to $callback
  • Parameter type added for parameter #1 ($callback): ?callable
  • Parameter name of parameter #2 changed: $error_types to $error_levels
  • Parameter type added for parameter #2 ($error_levels): int
  • Parameter default value added for position #2 ($error_levels): E_ALL
- set_error_handler($error_handler, $error_types)
+ set_error_handler(?callable $callback, int $error_levels = E_ALL)

set_error_handler Function Availability

PHP VersionAvailability
PHP 8.5Future Release Yes
PHP 8.4Upcoming Release Yes
PHP 8.3Supported (Latest) Yes
PHP 8.2Supported Yes
PHP 8.1Security-Fixes Only Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes