3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MyTrueException extends \Exception { } class MyFalseException extends \Exception { } function doSomething($var) { throw ($var) ? new MyTrueException() : new MyFalseException(); } try { doSomething(true); } catch (MyTrueException) { echo 'got true'; } catch (MyFalseException) { echo 'got false'; }
Output for 8.1.23 - 8.1.28, 8.2.10 - 8.2.18, 8.3.0 - 8.3.6
got true
Output for 5.4.0 - 5.4.25
Parse error: syntax error, unexpected ')', expecting variable (T_VARIABLE) in /in/afWlg on line 20
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected ')', expecting T_VARIABLE in /in/afWlg on line 20
Process exited with code 255.

preferences:
86.33 ms | 401 KiB | 82 Q