Re: RFC proposal: Invokable interface
| From: | Anton Smirnov | Date: | Sun, 29 Mar 2026 22:51:16 +0000 |
| Subject: | Re: RFC proposal: Invokable interface | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130484@lists.php.net to get a copy of this message | ||
Hi!
On 30/03/2026 00:42, Osama Aldemeery wrote:
It follows the Stringable pattern: auto-implemented for any class defining __invoke(), explicitly implementable with enforcement, and covariant to callable in return type checks.Stringable is just a normal interface that can be used directly as any other regular interface, it's just also applied magically. Invokable cannot be a regular interface because the signature for __invoke is not fixed, so it's a "weird" interface with magic behavior like Throwable and Iterable. What is common about these weird interfaces is that they can't be directly implemented by user. I don't feel like breaking this rule is a good idea for something with no clear benefits. Second thing is that magic methods are not supposed to be used directly, so having __invoke is just an implementation detail, the consumer code should not check for that, that's a code smell. Anton