On Fri, Dec 23, 2022, 7:46 PM joke2k <jok...@gmail.com> wrote: > Thanks for the feedback! > > On Fri, 23 Dec 2022, 09:33 Claude Pache, <claude.pa...@gmail.com> wrote: > > > It is very common for fluent class methods to have a verbose `return > > $this;` ending in their body. > > But If you have declared `self` as return type into a non-static class > > method you have only two options to return: > > > > - the $this object > > - another instance of the same class or subclass > > > > ... in order to avoid a return type error. > > > > > > It is still two options, and it is not clear in general which one to > pick. > > You could also say that, if you have `object` as return type, there are > two > > options to avoid a return type error: either return the `$this` object, > or > > return another object. > > > > Yes but declaring `self` is more strict than `object`. > And talking about the word itself... Declaring to return (your-)`self` but > you could return someone-else of the same type as you. > But it is ok, it refers to the class name not the instance. just semantic. >
I would rather endure it returns the used instance and not another one with a compatible interface. Not doing do is actually confusing to me, as per the meaning of self. . Or maybe, if the goal is to ease declaration of fluent interfaces (methods chaining), declaring a class fluent (annotation?) would achieve the same with ambiguous names? >