Re: [RFC] $this return type
| From: | Ben Ramsey | Date: | Thu, 09 Sep 2021 15:00:03 +0000 |
| Subject: | Re: [RFC] $this return type | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116026@lists.php.net to get a copy of this message | ||
> On Sep 9, 2021, at 09:47, Mike Schinkel <mike@newclarity.net> wrote:
>
>> On Sep 9, 2021, at 10:26 AM, Flávio Heleno <flaviohbatista@gmail.com> wrote:
>>
>> On Tue, Sep 7, 2021 at 10:27 AM Sebastian Bergmann <sebastian@php.net>
>> wrote:
>>
>>> Am 07.09.2021 um 12:28 schrieb Nikita Popov:
>>>> 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.
>>>
>>> I am not conviced that there is enough value in this to introduce syntax
>>> for it, but if at all, then please not "$this" as the name for a type.
>>>
>>> Off the top of my head, I think that "same" could make sense.
>>>
>>> --
>>> PHP Internals - PHP Runtime Development Mailing List
>>> To unsubscribe, visit: https://www.php.net/unsub.php
>>>
>>>
>> Hi all,
>>
>> I'm sorry if I'm being naive, or simply put dumb, but the main difference
>> that we're trying
>> to achieve with having "$this" (or variations of it) as a valid return type
>> as opposed to simply
>> using "self" is to ensure that the underlying code is actually doing a
>> "return $this" rather
>> than returning any other valid "self" instance (such as "return new
>> self();")?
>
> So a *mutable* fluent style vs. an *immutable* fluent style?
>
> -Mike
For clarity, in comparing to
Attachment: [application/pgp-signature] Message signed with OpenPGP signature.asc
self and static…
self
: the return value must be an instance of the same class that sets
this type declaration
static
: the return value must be an instance of the same class that calls
the method with this type declaration
$this
: the return value must be the same instance as the instance that
calls the method with this type declaration
Cheers,
Ben
Attachment: [application/pgp-signature] Message signed with OpenPGP signature.asc