3v4l.org

run code in 300+ PHP versions simultaneously
<?php function previous_handler(Throwable $e) { printf("This is the PREVIOUS handler for %s\n", $e->getMessage()); } //------------ class Configurator { public static function setupPhpErrorListener(): void { $controller = new PhpErrorController(); $controller->usePreviousExceptionHandler(set_exception_handler([$controller, 'onException'])); } } class PhpErrorController { private $previous = null; public function usePreviousExceptionHandler(?callable $previous): void { $this->previous = $previous; } public function onException(Throwable $throwable): void { printf("This is the WONOLOG handler for %s\n", $throwable->getMessage()); if ($this->previous === null) { throw $throwable; } ($this->previous)($throwable); } } //------------ set_exception_handler('previous_handler'); Configurator::setupPhpErrorListener(); throw new Exception('Test exception');

preferences:
41.88 ms | 405 KiB | 5 Q