On Wed, Feb 17, 2016 at 10:26 AM, Levi Morrison <le...@php.net> wrote:
> I want to add my personal experience with traits: every time I create > a trait it is to implement an interface. Here is a publicly available > [example with OuterIterator]( > https://github.com/morrisonlevi/Ardent/blob/master/src/Collection/OuterIteratorTrait.php > ): > > [snip] > > I can see how it would be nice to allow the trait to officially > declare that it implements some interface (in this case Iterator or > OuterIterator) which would require that the trait has fully > implemented the required methods (or declared them as abstract). This > would be a small improvement but helpful. > > I am less certain about the classes which `use` it automatically > inheriting the interfaces. To clarify: I am neither in favor or > against that part. Or at least at this stage, anyway. > I don't think there is enough benefit from allowing traits to declare interfaces, but not propagating the interface out to classes that insert the trait. It does provide an extra bit of enforcement on the trait's methods, but the real value is in making that contract a part of the classes. In what situation would a class that inserts OuterIterator not want to declare the Iterator class? If every class that inserts the trait would also declare Iterator, it's needless repetition to require that both the class and the interface. I assert that there is no useful case where a class would not want an interface declared by one of its traits, and this RFC proposes the same.