Why PHP Trait can't implement interfaces?

后端 未结 4 1152
暗喜
暗喜 2020-12-23 10:56

I\'m wondering why PHP Trait (PHP 5.4) cannot implement interfaces.

Update from user1460043\'s answer => ...cannot require class which uses it to implement a

4条回答
  •  萌比男神i
    2020-12-23 11:49

    There's a RFC: Traits with interfaces suggests following to be added to the language:

    trait SearchItem implements SearchItemInterface
    {
        ...
    }
    

    Methods required by the interface can either be implemented by the trait, or declared as abstract, in which case it is expected that class that uses the trait implements it.

    This feature is currently not supported by the language, but it is under consideration (current status of the RFC is: Under Discussion).

提交回复
热议问题