Re: Make Closure covariant to callable
| From: | Larry Garfield | Date: | Tue, 12 Nov 2024 22:32:26 +0000 |
| Subject: | Re: Make Closure covariant to callable | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-125947@lists.php.net to get a copy of this message | ||
On Tue, Nov 12, 2024, at 10:43 AM, Claude Pache wrote:
>> Le 12 nov. 2024 à 14:53, Gina P. Banyard <internals@gpb.moe> a écrit :
>>
>> Hello internals,
>>
>> Ondřej Mirtes (author of PHPStan) remarked to me in August that Closure is not a subtype
>> of callable.
>> The implementation of this is quite straight forward and can be seen on GitHub. [1]
>> The question is if there are any concern or not and if this requires an RFC or can just be
>> merged as is.
>>
>> Best regards,
>>
>> Gina P. Banyard
>>
>> [1] https://github.com/php/php-src/pull/15492
>
>
> Hi Gina,
>
> That seems reasonable.
>
> But personally, I would be more interested in having a type equivalent
> to
callable&object, that is all objects that implement the
> __invoke() magic method (this is a strict super-type of
> \Closure).
>
> —Claude
I am in favor of Closure being covarant to callable, and to a new pseudo-type for
Closure|Object-with-__invoke. (Maybe Invokable?) I do think they'd require brief RFCs, but
both would have my support.
--Larry Garfield