On 19/06/2023 22:12, David Gebler wrote:
Sure, but in this example were B::bar() to be a private method, you would get a scope violation error. You would not if you were to use a trait, since any methods implemented in the trait would be executed in the same scope as the class using the trait. And that seems to be what's being proposed here for interface defaults. So my concern here is that when you use a trait, you know that what you're doing is effectively copy-and-pasting implementation into your class scope. You don't expect that when you declare a class to implement an interface.
That's a crucially different example - it's not about whether the interface has to declare everything it uses, but about what scope it operates in.
The RFC should probably spell it out more clearly, but my interpretation was that the methods are being inherited just like if they were on an abstract class, not "pasted" like a trait - e.g. the example of delegating to an interface method would not work with a trait. As such, they would execute in the scope of the interface, and have access to protected but not private members of the class that inherits them.
This is also hinted at in the exchange between Levi and Alexandru about private methods on the interface itself, which would not be visible anywhere outside the interface. Again, that's different from traits, where members marked "private" are private to the target class, not the trait.
Regards, -- Rowan Tommins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php