Re: RFC proposal: Invokable interface
| From: | Rob Landers | Date: | Mon, 30 Mar 2026 07:58:03 +0000 |
| Subject: | Re: RFC proposal: Invokable interface | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130487@lists.php.net to get a copy of this message | ||
On Mon, Mar 30, 2026, at 09:37, Rowan Tommins [IMSoP] wrote:
> On 30 March 2026 01:32:24 BST, Osama Aldemeery <aldemeery@gmail.com> wrote:
>
> >The only difference is that __toString() has a fixed signature, so
> >Stringable can enforce it through a normal interface declaration.
> >__invoke() doesn't
> >have a fixed signature, so Invokable uses an enforcement handler instead.
> >Different mechanism, same contract. The difference is caused by the
> >variable signature, not by any fundamental difference in what the interface
> >represents.
>
> I think that is a very fundamental difference.
>
> Given $foo instanceof Stringable, the user knows they can write (string)$foo and the object
> will do something - that's already a pretty weak contract, in my eyes, but it is a contract.
>
> Given $foo instanceof Invokable, the user knows even less. They know they can invoke the object
> somehow, but there's a fair chance that $foo() will fail because of mandatory parameters.
>
> Can you give an example where this very loose contract would be useful?
>
> Regards,
>
> Rowan Tommins
> [IMSoP]
I'd prefer if the interface forced an empty argument set. You can add arguments so long as
they're optional. But generally speaking, there is no need for arguments on an invokable class
-- that is what constructors and properties are for.
— Rob