3v4l.org

run code in 300+ PHP versions simultaneously
<?php /*set_exception_handler(function ($e) { var_dump($e->getMessage()); throw 1; });*/ function unhandled(Exception $e) { // set dummy handler and return previous handler $handler = set_exception_handler(function ($e) { var_dump($e); throw 1; }); // use dummy handler when no original handler is available if ($handler === null) { $handler = set_exception_handler(null); } set_exception_handler(null); try { $handler($e); } catch (Exception $e) { var_dump('foo', $e); } echo 'die'; die(255); } echo 1; unhandled(new RuntimeException('fatal error')); echo 2;
Output for 8.4.1 - 8.4.12
1object(RuntimeException)#1 (7) { ["message":protected]=> string(11) "fatal error" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/ktOfm" ["line":protected]=> int(33) ["trace":"Exception":private]=> array(0) { } ["previous":"Exception":private]=> NULL } Fatal error: Uncaught Error: Can only throw objects in /in/ktOfm:13 Stack trace: #0 /in/ktOfm(24): {closure:unhandled():11}(Object(RuntimeException)) #1 /in/ktOfm(33): unhandled(Object(RuntimeException)) #2 {main} thrown in /in/ktOfm on line 13
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25
1object(RuntimeException)#1 (7) { ["message":protected]=> string(11) "fatal error" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/ktOfm" ["line":protected]=> int(33) ["trace":"Exception":private]=> array(0) { } ["previous":"Exception":private]=> NULL } Fatal error: Uncaught Error: Can only throw objects in /in/ktOfm:13 Stack trace: #0 /in/ktOfm(24): {closure}(Object(RuntimeException)) #1 /in/ktOfm(33): unhandled(Object(RuntimeException)) #2 {main} thrown in /in/ktOfm on line 13
Process exited with code 255.

preferences:
151.77 ms | 410 KiB | 5 Q