Re: [RFC] $this return type

From: Date: Tue, 07 Sep 2021 13:02:28 +0000
Subject: Re: [RFC] $this return type
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-115992@lists.php.net to get a copy of this message
Hey Nikita On 07.09.21 12:28, Nikita Popov wrote:
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. Regards, Nikita
If we allow a $this (let's keep the actual naming out for the moment) as a returntype to clarify that it has to be the same instance that is returned, I would also either expect that the returntype 'self' does explicitly *not* allow the same instance to be returned. As that would be a huge BC break I would on the other hand also think that we should implement a returntype "!$this" to explicitly state that the contract here returns *not* the current instance but a new one. That way a lot of immutable contracts could be made more clear. What'S your or others idea regarding that? Cheers Andreas -- ,,, (o o) +---------------------------------------------------------ooO-(_)-Ooo-+ | Andreas Heigl | | mailto:andreas@heigl.org N 50°22'59.5" E 08°23'58" | | https://andreas.heigl.org | +---------------------------------------------------------------------+ | https://hei.gl/appointmentwithandreas | +---------------------------------------------------------------------+

Attachment: [application/pgp-keys] OpenPGP public key OpenPGP_0xA8D5437ECE724FE5.asc
Attachment: [application/pgp-signature] OpenPGP digital signature OpenPGP_signature.asc
« previous php.internals (#115992) next »