3v4l.org

run code in 200+ 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.1
bar baz qux
Output for 7.1.0 - 7.3.13
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.