Traits vs. interfaces

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

    Traits are simply for code reuse.

    Interface just provides the signature of the functions that is to be defined in the class where it can be used depending on the programmer's discretion. Thus giving us a prototype for a group of classes.

    For reference- http://www.php.net/manual/en/language.oop5.traits.php

提交回复
热议问题