3v4l.org

run code in 200+ PHP versions simultaneously
<?php class A { protected $thing; public function __construct($thing) { $this->thing = $thing; } public static function create() { return new static('foo'); } } class B extends A { protected $another; public function getAnother() { return $this->another; } public static function create() { $instance = parent::create(); $instance->another = 'bar'; return $instance; } } var_dump(B::create()->getAnother());
Output for 5.6.38 - 7.4.0rc1
string(3) "bar"