Traits vs. interfaces

前端 未结 13 1308
傲寒
傲寒 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:29

    If you know English and know what trait means, it is exactly what the name says. It is a class-less pack of methods and properties you attach to existing classes by typing use.

    Basically, you could compare it to a single variable. Closures functions can use these variables from outside of the scope and that way they have the value inside. They are powerful and can be used in everything. Same happens to traits if they are being used.

提交回复
热议问题