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