Hi
Am 2025-03-20 17:09, schrieb Gina P. Banyard:
And another user [2] was basically suggesting my previous solution of
adding support for type classes/runtime implementation of interfaces.
[…]
[2] https://www.reddit.com/r/PHP/comments/1jbcbtx/comment/mhvxo5j/
I don't see how this could (usefully) work in PHP, which doesn't scope
the methods on a “per interface” basis / which makes methods just some
syntactic sugar for a function that takes the object as a parameter.
Once you have more than a handful of interfaces on a single object you
are bound to have naming / signature conflicts, unless the interfaces
use some oddly-specific name for their methods. Two different
serialization libraries might want to use `serialize()` for their
methods, but using incompatible signatures (e.g. to pass additional
options).
It works well for Rust, since each trait will need to be imported
explicitly for the associated methods to be available. And then you can
also call the method as a free-standing function, just passing the
appropriate struct as a parameter to disambiguate them.
Best regards
Tim Düsterhus