Re: [VOTE] Optional Interfaces

From: Date: Fri, 21 Mar 2025 09:50:28 +0000
Subject: Re: [VOTE] Optional Interfaces
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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

Thread (12 messages)

« previous php.internals (#126883) next »