3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Foo { public function returnBool() { return random_int(0,1) > 0; } } function returnsBool(?Foo $foo): bool { return $foo?->returnBool(); } var_dump(returnsBool(null));
Output for 8.0.0 - 8.0.3
Fatal error: Uncaught TypeError: returnsBool(): Return value must be of type bool, null returned in /in/mS4VP:10 Stack trace: #0 /in/mS4VP(13): returnsBool(NULL) #1 {main} thrown in /in/mS4VP on line 10
Process exited with code 255.
Output for 7.3.0 - 7.3.27, 7.4.0 - 7.4.16
Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /in/mS4VP on line 10
Process exited with code 255.

preferences:
51.39 ms | 687 KiB | 4 Q