3v4l.org

run code in 300+ PHP versions simultaneously
<?php function functionCall4() { if (true or mt_rand(1, 4) === 2) { throw new \Exception('exception'); } } function functionCall3() { functionCall4(); } function functionCall2() { functionCall3(); } function functionCall1() { try { functionCall2(); } catch (\Exception $e) { throw new \RuntimeException($e->getMessage(), $e->getCode(), $e); } } try { functionCall1(); } catch (\RuntimeException $e) { echo 'Exception caught', PHP_EOL; while ($e) { echo 'Trace for ', get_class($e), "\n"; print_r($e->getTrace()); $e = $e->getPrevious(); } }
Output for 8.1.23 - 8.1.33, 8.2.3 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Exception caught Trace for RuntimeException Array ( [0] => Array ( [file] => /in/vDt7v [line] => 31 [function] => functionCall1 [args] => Array ( ) ) ) Trace for Exception Array ( [0] => Array ( [file] => /in/vDt7v [line] => 13 [function] => functionCall4 [args] => Array ( ) ) [1] => Array ( [file] => /in/vDt7v [line] => 18 [function] => functionCall3 [args] => Array ( ) ) [2] => Array ( [file] => /in/vDt7v [line] => 24 [function] => functionCall2 [args] => Array ( ) ) [3] => Array ( [file] => /in/vDt7v [line] => 31 [function] => functionCall1 [args] => Array ( ) ) )

preferences:
78.29 ms | 410 KiB | 5 Q