Re: [PHP-DEV] Methods which auto-return the class instance

2022-12-23 Thread Claude Pache
> Le 23 déc. 2022 à 01:08, joke2k a écrit : > > Hi folks, > > What do you think about having a method which returns the class instance > `$this` by default only IF its return type is set as `self`? > > It is very common for fluent class methods to have a verbose `return > $this;` ending in the

Re: [PHP-DEV] Methods which auto-return the class instance

2022-12-23 Thread Lynn
On Fri, Dec 23, 2022 at 10:33 AM Claude Pache wrote: > > ```php > public function hit(): $this { $this->counter++; } > ``` > > Here, there is only one possible return value, and therefore the `return` > instruction might be reasonably omitted. > > The real question is: Is it worth to add special

Re: [PHP-DEV] Methods which auto-return the class instance

2022-12-23 Thread Michał Marcin Brzuchalski
Hi Daniele and Claude, pt., 23 gru 2022 o 10:33 Claude Pache napisał(a): > > > Le 23 déc. 2022 à 01:08, joke2k a écrit : > > > > Hi folks, > > > > What do you think about having a method which returns the class instance > > `$this` by default only IF its return type is set as `self`? > > > > It

Re: [PHP-DEV] Methods which auto-return the class instance

2022-12-23 Thread joke2k
Thanks for the feedback! On Fri, 23 Dec 2022, 09:33 Claude Pache, 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: >

Re: [PHP-DEV] Methods which auto-return the class instance

2022-12-23 Thread Claude Pache
> Le 23 déc. 2022 à 13:46, joke2k a écrit : > > On Fri, 23 Dec 2022, 09:33 Claude Pache, > 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

Re: [PHP-DEV] Methods which auto-return the class instance

2022-12-23 Thread Robert Landers
On 12/23/22, joke2k wrote: > Hi folks, > > What do you think about having a method which returns the class instance > `$this` by default only IF its return type is set as `self`? > > It is very common for fluent class methods to have a verbose `return > $this;` ending in their body. > But If you h