3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ExHandler { public static function handle(Exception $e) { $label = 'Uncaught'; foreach(self::generate($e) as $cur) { printf("%s %s: %s\nStack Trace:\n%s\n\n", $label, get_class($cur), $cur->getMessage(), preg_replace('/^/m', ' ', $cur->getTraceAsString()) ); $label = 'Next'; } printf("Thrown in %s on line %d\n", $e->getFile(), $e->getLine()); printf("Custom shit over\n"); set_exception_handler(null); throw $e; } protected static function generate(Exception $e) { $prev = $e->getPrevious(); if( ! is_null($prev) ) { foreach( self::generate($prev) as $cur ) { yield $cur; } } yield $e; } } class Foo { public function bork() { $first = new Exception('I happened first!'); $second = new Exception('I happened second!', 0, $first); throw new Exception('fission mailed', 0, $second); } } set_exception_handler(['ExHandler', 'handle']); (new Foo())->bork(); /* Fatal error: Uncaught Exception: I happened earlier! in /in/F4B7q:5 Stack trace: #0 /in/F4B7q(10): Foo->bork() #1 {main} Next Exception: fission mailed in /in/F4B7q:6 Stack trace: #0 /in/F4B7q(10): Foo->bork() #1 {main} thrown in /in/F4B7q on line 6 */
Output for 7.1.0 - 7.1.33, 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Uncaught Exception: I happened first! Stack Trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} Next Exception: I happened second! Stack Trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} Next Exception: fission mailed Stack Trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} Thrown in /in/F8eG9 on line 34 Custom shit over Fatal error: Uncaught Exception: I happened first! in /in/F8eG9:32 Stack trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} Next Exception: I happened second! in /in/F8eG9:33 Stack trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} Next Exception: fission mailed in /in/F8eG9:34 Stack trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} thrown in /in/F8eG9 on line 34
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Uncaught Exception: I happened first! Stack Trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} Next Exception: I happened second! Stack Trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} Next Exception: fission mailed Stack Trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} Thrown in /in/F8eG9 on line 34 Custom shit over Fatal error: Uncaught Exception: I happened first! in /in/F8eG9:32 Stack trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} Next Exception: I happened second! in /in/F8eG9:33 Stack trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} Next Exception: fission mailed in /in/F8eG9:34 Stack trace: #0 /in/F8eG9(40): Foo->bork() #1 {main} thrown in /in/F8eG9 on line 34
Process exited with code 255.

preferences:
166.15 ms | 402 KiB | 206 Q