Hi everyone. I've been lurking for a couple of days, but fwiw, I think this RFC makes more sense as a built-in annotation.
Something like #[partialImplemenation(Countable::class)] trait PropertyCount { public function count(): int { return count(get_object_vars($this)); } } Adding new syntax for this doesn't seem like it would provide any useful abilities or optimizations in the language (I could be wrong) but are more useful to developers and tooling. A built-in annotation would allow tooling to introspect the engineer's intentions as well as allow devs to not care, if they want to and/or know what they're doing. I'd actually suggest two annotations: expectsImplementation and partialImplementation. expectsImplementation would mean that it expects those methods from the given class/interface/trait to be present where it is used, while partialImplementation indicates that it implements some (or all) of a child interface/class. Robert Landers Software Engineer Utrecht NL On Fri, Jan 7, 2022 at 10:01 AM Rowan Tommins <rowan.coll...@gmail.com> wrote: > On 06/01/2022 23:53, Robert Korulczyk wrote: > > But there is no easy way to say "`FooTrait::someMethod()` is > > implementation of `FooInterface::someMethod()`" that PHP and SCA will > > understand. And I think this proposal handles this quite well > > > I'm not convinced it does, actually. Consider the following trait: > > trait PropertyCount { > public function count(): int { > return count(get_object_vars($this)); > } > } > > This trait CAN be used to implement the built-in Countable interface, > and it might be useful to label it as such; but does it really make > sense to say that classes MUST implement that interface? > > Even if we put it as a requirement, we can't guarantee that the class > will actually use the trait's implementation of the interface, because > this would still be valid: > > class Foo implements Countable { > private $whatever; > > use PropertyCount { > count as getPropertyCount; > } > > public function count(): int { > return 0; > } > } > > > It feels like this use case would work better with an annotation like > /** @can-implement Countable */ since it is really just documentation > about possible uses. > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >