On Thu, 9 Jan 2020 at 15:22, Andreas Hennings <andr...@dqxtech.net> wrote:
> > However, $this is not a real type, and it is unclear what the advantage > of specifying $this rather than static would be from a type system level > perspective. > > Perhaps not from a "type system level", but from a more broad "enforced > contract" level. > E.g. IDEs or code inspection tools can warn if a method will not return > $this. > This also means recursive calls also need to return $this instead of > static. > > class C { > function foo(): static { > return clone $this; > } > function bar(): $this { > return $this->foo(); // IDE can complain. > } > } > Of course this ": $this" could be added later in the future. But this would have the risk that people start adding ": static" on methods that really return $this. This would cause confusion if later some packages introduce ": $this", but others are still behind. namespace oldpackage; class B { function foo(): static { // Actually returns $this, not just static. return $this; } } namespace newpackage; class C extends B { function foo(): $this { return parent::foo(); // Should the IDE complain? } } > > > On Thu, 9 Jan 2020 at 15:07, Larry Garfield <la...@garfieldtech.com> > wrote: > >> On Wed, Jan 8, 2020, at 5:42 AM, Nikita Popov wrote: >> > Hi internals, >> > >> > I would like to propose the following RFC, which allows using "static" >> as a >> > return type: >> > >> > https://wiki.php.net/rfc/static_return_type >> > >> > While I'm personally not a fan of late static binding, we do support it >> and >> > people do use it quite heavily, so I think we should also support it in >> > return types. >> > >> > Regards, >> > Nikita >> >> >> Is "squee!" an appropriate response on the list? For interface authors >> this is a huge deal. >> >> --Larry Garfield >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >>