On 30 March 2026 01:32:24 BST, Osama Aldemeery <[email protected]> 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]

Reply via email to