Extend Traits with Classes in PHP?

后端 未结 3 1448
萌比男神i
萌比男神i 2020-12-29 19:59

Why we are not allowed to extend Traits with Classes in PHP?

For example:

Trait T { }

Class C use T {}
/*          


        
3条回答
  •  执笔经年
    2020-12-29 20:16

    Only classes can be extended. Traits are not classes. They can be used/included by classes but are not classes themselves. If you think a trait needs to be extended then it probably should be a class, probably an abstract one, and not a trait.

提交回复
热议问题