get_exception_handler
get_exception_handler
Gets the user-defined exception handler function
**get_exception_handler**
Returns the current exception handler function, if any.
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
to define it.
set_exception_handler
Voorbeeld: 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)
?>
Tip: > 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; } } ?>
set_exception_handler``restore_exception_handler``restore_error_handler``error_reportingExceptions