Re: [RFC] Interface Default Methods

From: Date: Mon, 19 Jun 2023 02:53:02 +0000
Subject: Re: [RFC] Interface Default Methods
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-120614@lists.php.net to get a copy of this message
On Sat, Jun 17, 2023 at 4:10 PM David Gebler <davidgebler@gmail.com> wrote: > > On Thu, Jun 15, 2023 at 4:48 AM Levi Morrison via internals <internals@lists.php.net> > wrote: >> >> >> I am moving my RFC for interface default methods to discussion: >> https://wiki.php.net/rfc/interface-default-methods. >> > > Can I ask, the RFC doesn't say - does your implementation ensure default implementations > can only call other methods which exist on the interface in the same manner as Java? i.e. the > following would give some sort of error? > > interface A { > public function foo(): void { > $this->bar(); > } > } > > class B implements A { > public function bar(): void { > ... > } > } > > But the following would be okay? > > interface A { > public function foo(): void { > $this->bar(); > } > > public function bar(): void; > } > No, there's no attempt to ensure the method body adheres to calling the public interface. Due to PHP's possible dynamic behaviors, I don't think it's reasonable to attempt to enforce it at compile-time. I'm not sure it's worth the effort trying to enforce it at runtime either, but it would be nice to see lints from static analysis tools which detect this issue.

« previous php.internals (#120614) next »