Re: RFC proposal: Invokable interface
| From: | Rowan Tommins [IMSoP] | Date: | Mon, 30 Mar 2026 07:37:19 +0000 |
| Subject: | Re: RFC proposal: Invokable interface | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130486@lists.php.net to get a copy of this message | ||
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]