Re: [VOTE] Optional Interfaces

From: Date: Fri, 21 Mar 2025 11:17:55 +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
On 2025-03-20 18:09, Gina P. Banyard wrote:

And another user [2] was basically suggesting my previous solution of adding support for type classes/runtime implementation of interfaces.
Hey, There are two ideas -- the $object implements Iface that you suggested and the SomeClass implements Iface that was suggested on reddit. I see the instance-specific one as something that a consumer can do in their project if they know that the $object actually fits where needed. That would be a cool feature per se. But it seems to me it would take a lot of bridging code to provide such "dynamically implementing" objects if you're the package author. I'll address the SomeClass implements Iface expression vs `class SomeClass implements ?Iface` hereinafter. The ?OptionalInterface would always be within the class definition and in a real-life project with PSR-4 you could check the interface existence by inspecting the file tree or click-throughing the name in an IDE. It's not obvious to me how the runtime implementation expressions could be in such a discoverable spot. The expression could be anywhere in the project. And it will likely be inside conditionals. It would surely be hard to discover manually. I'm not a developer of stan tooling, but I expect it would complicate automated static analysis as well. BR, Juris

Thread (12 messages)

« previous php.internals (#126891) next »