On Thu, Feb 18, 2016 at 2:16 PM, Chase Peeler <chasepee...@gmail.com> wrote:

>
>
> On Thu, Feb 18, 2016 at 1:29 PM Nikita Popov <nikita....@gmail.com> wrote:
>
>> HHVM already supports "trait Foo implements Iface" with the semantics that
>> the interface is also implemented by the using class.
>>
>> Additionally HHVM supports a notion of "require implements Iface" which
>> means that the using class must implement this interface.
>>
>
This was mentioned in the original traits RFC, but never got voted or
implemented:
https://wiki.php.net/rfc/horizontalreuse#requiring_composing_class_to_implement_interface

It's orthogonal to this RFC.


>
>> Why should it matter if the class using the trait actually implements the
> interface? If the person just wants the functionality, but, for whatever
> reason, doesn't want to actually implement the interface, why should it
> matter?
>
> I think the trait should HELP the person implementing an interface. The
> trait should be able to say (whether via comments or an engine enforceable
> construct) "Hey, I've done everything needed for you to implement this
> interface" but, at no time, should the trait force the class utilizing it
> to interact (via extend or implement or use) a 3rd artifact.
>
> trait foo implements myinterface {}
> class bar { use foo;}
> class baz implements myinterface { use foo;}
>
> Both of the above should be legal, and $myBar instanceof myinterface
> should return false;
>

This is Proposal 1 in the new draft of my RFC:
https://wiki.php.net/rfc/traits-with-interfaces

Does that proposal sound like what you'd want?

Cheers
-- Kevin

>

Reply via email to