get_error_handler

(PHP 8 >= 8.5.0)

get_error_handlerGets the user-defined error handler function

说明

get_error_handler(): ?callable

Returns the current error handler function, if any.

参数

此函数没有参数。

返回值

Returns the currently defined error handler (if any). If the built-in error handler is used null is returned.

The returned handler is the exact callable value that was passed to set_error_handler() to define it.

示例

示例 #1 get_error_handler() example

<?php

$handler
= function (int $errno, string $errstr, ?string $errfile, ?int $errline) {
echo
"Error: " . $errstr . "\n";
};

var_dump(get_error_handler()); // NULL

set_error_handler($handler);

var_dump(get_error_handler() === $handler); // bool(true)

?>

注释

小技巧

Prior to PHP 8.5.0, this functionality can be provided by the following polyfill:

<?php
if (!function_exists('get_error_handler')) {
function
noop_error_handler() {
}
function
get_error_handler(): ?callable {
$handler = set_error_handler('noop_error_handler');
restore_error_handler();
return
$handler;
}
}
?>

参见

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top