Traits vs. interfaces

前端 未结 13 1141
傲寒
傲寒 2020-11-28 17:09

I\'ve been trying to study up on PHP lately, and I find myself getting hung up on traits. I understand the concept of horizontal code reuse and not wanting to necessarily in

相关标签:
13条回答
  • 2020-11-28 17:51

    An interface is a contract that says “this object is able to do this thing”, whereas a trait is giving the object the ability to do the thing.

    A trait is essentially a way to “copy and paste” code between classes.

    Try reading this article, What are PHP traits?

    0 讨论(0)
提交回复
热议问题