On Friday 07 November 2025 18:05:03 (+01:00), Spencer Malone wrote:
> Hey all! Long time browser, first time emailer. I wanted to start a
pre-RFC
> discussion on the proposal of opt-in implicit interfaces / structural
> typing / "golang style interfaces".
>
> I have an early mostly working POC at
>
https://github.com/php/php-src/compare/master...SpencerMalone:php-src:implicit,
and was curious if this was an idea that could get any traction as an
RFC?
>
> For those who don't want to open the link, it's essentially:
>
> ```
> implicit interface Drawable {
> public function draw(): void;
> }
If you may be that kind and allow an implicit interface to use a trait...
>
> class Circle {
> public function draw(): void {
> }
> }
>
... then the class could use a trait as well which is then closing the
distance to traits that are not able to full-fill interfaces and their
using classes, so the classes can borrow from the traits and both then
somewhat profit from implicit interfaces.
The "innerface" naturally could only use the non-body parts (abstract
parts) of the trait methods / properties, so the copy direction towards
the interface is a reduction to the interface the trait implies.
The trait then can be used in the implicit interface definition to do
both at once (defining an interface and providing an implementation).
>
> assert((new Circle()) instanceof Drawable); // This would be true
> ```
>
and if I may add, truly great - regardless with or without such
trait reuse.
if it then could work en-par with function defintions (define after
use which currently "explicit" interfaces are not capable of) this
would make it a perfect and modern addition to the language in my
very own eyes.
> There is some previous art around here in the form of...
> [...]
>
> - Spencer
>
- h.k.