Re: [RFC] Traits with interfaces
| From: | Chase Peeler | Date: | Wed, 17 Feb 2016 15:00:31 +0000 |
| Subject: | Re: [RFC] Traits with interfaces | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-91247@lists.php.net to get a copy of this message | ||
I agree. with Sebastian. I'm personally a big fan of using traits as the
implementation mechanism for interfaces (i.e. implement the interfaces
methods in a trait, then use that trait in a class that implements the
interface), but I don't think there is anything positive to gain from
having the trait actually implement the interface.
On Wed, Feb 17, 2016 at 9:34 AM Sebastian Bergmann <sebastian@php.net>
wrote:
> Am 17.02.2016 um 15:25 schrieb Kevin Gessner:
> > Hello internals team! I'd like to propose an RFC to allow traits to
> > implement interfaces.
>
> I think that would violate "The Flattening Property" [1], meaning
> that the fact that a class uses a trait must not be noticable by a
> user of that class.
>
> Also bear in mind that explicit is better than implicit. Two
> explicit declarations, "implements <interface>" and "uses
> <trait>",
> makes it obvious from looking at the code of a class that is
> provides a specific API and uses a trait for its implementation.
>
> Exactly. Not to mention that interfaces are "types" (i.e. $object
instanceof MyInterface will be true if $object is an instance of a class
that implements MyInterface) while traits are not. By moving the
"implements MyInterface" into the trait, you "hide" and important attribute
of the class that should be obvious and explicit.
> --
> [1] https://wiki.php.net/rfc/horizontalreuse
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
-- Chase
chasepeeler@gmail.com