Your other points make sense, but I don't think this one does - there are no
implicit interfaces in PHP*, so all any tool cares about is:
1) Does the class declaration say that it implements an interface?
2) Does it actually contain the methods needed to do so, through any
combination of direct implementation, inheritance, and trait usage?
Knowing that a particular trait *could be* used to implement a particular interface without further code doesn't really tell the tool anything - it still has to resolve the list of methods on the class itself, and test those against the "implements" clause.
You're talking about classes that use traits, but I'm talking about traits themselves. If I open a class in editor, there is a straightforward way to
check if specific method is implementation of an interface - check interfaces implemented by class and if one of them have this method, then this
method is implementation of this interface, and editor can properly mark it and handle navigation between implementation in class and declaration in
interface. So even if I have a big project, you need to only load a subset of classes used by this project in order to find methods that are
implementations of interfaces in this particular class.
If I open trait in my editor, it is a lot more complicated. Editor needs to scan the whole project, find all classes that use this trait, find all
interfaces that are implemented by these classes, and then find matches. And you may still end up with confusing results, because if you have class
`A` that implements `FooInterface` and uses `FooTrait`, and also class `B` that uses `FooTrait`, but NOT implements `FooInterface`, then if you ask if
`FooTrait::someMethod()` is implementation of `FooInterface::someMethod()`, the answer is "yes and no".
Also, I'm not sure how it works now, but about 2 years ago I got rid of most of traits in one project, because navigation between trait and interface
worked so badly in PhpStorm, that it was easier to deal with code duplication than broken "implements" detection. At the same time navigation between
classes and interfaces worked without any problem.
--
Regards,
Robert Korulczyk
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php