trait (PHP)
trait in PHP
PHP のトレイトに気をつける - tototoshi の日記
Cake PatternをPHPでやると依存関係がわからなくなって可読性がものすごく落ちる(やるべきでない)
Scalaなら依存関係はわかるしコンパイルエラーになる
Laravelから学ぶPHPのTraitの使い所 - Qiita
メソッドの共通化(traitの説明として最もよく使われる)
Interfaceに実装をもたせる
interfaceに対応するtraitをつくってclassから両方使う
Traitの関数にクラス内のローカルな名前をつけて呼び出す - Qiita
機能のグルーピング
PHP: rfc:horizontalreuse
Traits is a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies. The semantics of the combination of Traits and classes is defined in a way, which reduces complexity and avoids the typical problems associated with multiple inheritance and Mixins.
As already mentioned, multiple inheritance and Mixins are complex mechanisms. Traits are an alternative which have been designed to impose no additional semantics on classes. Traits are only entities of the literal code written in your source files. There is no notion about Traits at runtime. They are used to group methods and reuse code and are totally flattened into the classes composed from them. It is almost like a language supported and failsafe copy'n'paste mechanism to build classes.