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

2022-12-27 Thread Pierre Joye
On Fri, Dec 23, 2022, 7:46 PM joke2k wrote: > 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-st

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

2022-12-24 Thread Stephen Reay
> On 25 Dec 2022, at 12:59, Ilija Tovilo wrote: > > Hi Daniele > >> On Fri, Dec 23, 2022 at 1:09 AM 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

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

2022-12-24 Thread Ilija Tovilo
Hi Daniele On Fri, Dec 23, 2022 at 1:09 AM 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;` end

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

2022-12-24 Thread Rowan Tommins
On 23 December 2022 13:29:07 GMT, Claude Pache wrote: >> 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 no

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

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 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 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 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 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

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

2022-12-22 Thread joke2k
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 have declared `self` as return type into a