3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $bar; public function __construct($bar) { $this->bar = $bar; } public function getBar() { return $this->bar; } } class Baz extends Foo { private $wrapped; public function __construct($bar) { $this->wrapped = $this->wrapped ?: (new \ReflectionClass('Foo'))->newInstanceWithoutConstructor(); $this->wrapped->__construct($bar); } public function getBar() { return $this->wrapped->getBar(); } } var_dump((new Baz('tab'))->getBar());

preferences:
53.03 ms | 402 KiB | 5 Q