3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected string $bar; protected string $baz; protected string $qux = 'initial qux'; public function fillValues() { $this->bar = 'bar'; $this->baz = 'baz'; $this->qux = 'qux'; } public function getBar() { return $this->bar; } public function getBaz() { return $this->baz; } public function getQux() { return $this->qux; } } $rc = new ReflectionClass(Foo::class); $foo = $rc->newInstanceWithoutConstructor(); $foo->fillValues(); echo $foo->getBar() . PHP_EOL; echo $foo->getBaz() . PHP_EOL; echo $foo->getQux() . PHP_EOL;
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
bar baz qux
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 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/U8t8M on line 5
Process exited with code 255.

preferences:
194.63 ms | 402 KiB | 207 Q