1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
--TEST-- Return type allows self --FILE-- <?php class Foo { public static function getInstance() : self { return new static(); } } class Bar extends Foo {} var_dump(Foo::getInstance()); var_dump(Bar::getInstance()); --EXPECTF-- object(Foo)#%d (%d) { } object(Bar)#%d (%d) { }