3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyException extends Exception { public static function throw($message) { throw new static($message); } } try { $nothing ?? MyException::throw('hooray'); } catch (Exception $e) { echo "Exception caught: $e"; }
Output for 7.0.0 - 7.0.33, 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.24, 8.2.0 - 8.2.11
Exception caught: MyException: hooray in /in/e49n2:7 Stack trace: #0 /in/e49n2(12): MyException::throw('hooray') #1 {main}
Output for 5.6.0 - 5.6.40
Parse error: syntax error, unexpected 'throw' (T_THROW), expecting identifier (T_STRING) in /in/e49n2 on line 5
Process exited with code 255.

preferences:
53.32 ms | 406 KiB | 5 Q