Hi Nikita Hi internals, > > I'd like to pick up a loose thread from the future scope of the > https://wiki.php.net/rfc/static_return_type RFC, the $this return type for > fluent APIs: > > https://wiki.php.net/rfc/this_return_type > > I have some reservations about this (which basically come down to $this not > being a proper "type", so should it be in the type system?) but I can see > the practical usefulness, so I think it's worth discussing this. >
Thank you so much for the RFC. I'm really looking forward to being able to use $this as a return type. > On a dataset of 2k composer packages, @return $this occurs 29k times, while @return static is used 38k times This is really good to know. It makes it pretty clear to me that being able to declare $this as a return value would be valuable to many projects! As far as my experience is concerned, I tried switching from the `@return $this` annotation to `function (): static`, which is the closest approximation currently supported by the engine, when I realized that this would loosen the semantics of the corresponding interfaces and kinda force ppl to deal with the return value while this doesn't make sense in fluent-style APIs. I therefore kept the annotation in place and I'm now looking forward to being able to write this declaration using native syntax - with the added benefit of having it enforced by the engine. About the syntax, I think the one proposed in the RFC is crystal clear. I've been used to seeing the "$" symbol when reading `@return $this`, and this just makes sense, past the first surprise. I also think that using "this" (without the dollar) could too easily be confused with something that means our "static" (esp. considering that TypeScript uses "this" in place of our "static".) I'm reading in responses that $this is not a type, but I fail to understand how that makes it an argument against the RFC. Neither false is a type, and null is both a type and a value. Yet we have them because they provide clear added value. Having $this could benefit 29k times the top 2k packages. It doesn't look like a niche use case! As you might have understood, I support the RFC and would vote for it as is personally! Nicolas