get_exception_handler

(PHP 8 >= 8.5.0)

get_exception_handlerGets the user-defined exception handler function

Açıklama

get_exception_handler(): ?callable

Returns the current exception handler function, if any.

Bağımsız Değişkenler

Bu işlevin bağımsız değişkeni yoktur.

Dönen Değerler

Returns the currently defined exception handler. If no handler is defined, null is returned.

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

Örnekler

Örnek 1 get_exception_handler() example

<?php

$handler
= function (Throwable $ex) {
echo
"Exception: " . $ex::class . ": " . $ex->getMessage() . "\n";
};

var_dump(get_exception_handler()); // NULL

set_exception_handler($handler);

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

?>

Notlar

İpucu

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

<?php
if (!function_exists('get_exception_handler')) {
function
noop_exception_handler() {
}
function
get_exception_handler(): ?callable {
$handler = set_exception_handler('noop_exception_handler');
restore_exception_handler();
return
$handler;
}
}
?>

Ayrıca Bakınız

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top