3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo {} function OptionalFoo(Foo $foo = null) { echo func_num_args(); } function NullableFoo(?Foo $foo) { echo func_num_args(); } OptionalFoo(); NullableFoo();
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.33, 7.4.3 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
0 Fatal error: Uncaught ArgumentCountError: Too few arguments to function NullableFoo(), 0 passed in /in/jStRZ on line 15 and exactly 1 expected in /in/jStRZ:9 Stack trace: #0 /in/jStRZ(15): NullableFoo() #1 {main} thrown in /in/jStRZ on line 9
Process exited with code 255.
Output for 5.6.0 - 5.6.25, 7.0.0 - 7.0.10
Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /in/jStRZ on line 9
Process exited with code 255.

preferences:
160.07 ms | 402 KiB | 178 Q