3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public int $bar; public function __get($name) { //return 'string'; // Can no longer do this return 999; // Type has to match } } $foo = new Foo(); var_dump($foo->bar);
Output for 7.4.1 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.21, 8.3.0 - 8.3.9
Fatal error: Uncaught Error: Typed property Foo::$bar must not be accessed before initialization in /in/flce2:16 Stack trace: #0 {main} thrown in /in/flce2 on line 16
Process exited with code 255.
Output for 7.4.0
int(999)
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/flce2 on line 5
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
Parse error: syntax error, unexpected 'int' (T_STRING), expecting variable (T_VARIABLE) in /in/flce2 on line 5
Process exited with code 255.

preferences:
169.46 ms | 403 KiB | 337 Q