3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private int $foo = 123; private array $bar = ['a' => 'b']; public function & __get(string $name) { return $this->$name; } } $foo = new Foo; var_dump($foo); $foo->foo = 456; $foo->bar['c'] = 'd'; var_dump($foo);
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
object(Foo)#1 (2) { ["foo":"Foo":private]=> int(123) ["bar":"Foo":private]=> array(1) { ["a"]=> string(1) "b" } } Fatal error: Uncaught Error: Cannot access private property Foo::$foo in /in/dn1cQ:17 Stack trace: #0 {main} thrown in /in/dn1cQ on line 17
Process exited with code 255.
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/dn1cQ 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/dn1cQ on line 5
Process exited with code 255.

preferences:
52.59 ms | 409 KiB | 5 Q