Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私が知る限り、疑似多重継承を提供する PHP の特性が存在します...そしてそれらを見ると、戻り値の型が関数と同じであることを除けば、むしろ構造体を思い起こさせます。
とにかく - インターフェイスや別の関数ではまだ実行できない特性で何ができますか?
トレイトは型情報を持たないため、インターフェイスとの共通点はありません。
class Test implements TestInterface { use TestTrait; } $x = new Test; var_dump( $x instanceof TestInterface ); // true var_dump( $x instanceof TestTrait ); // false
全体として、トレイトは、コピー アンド ペーストに頼らずにコードを繰り返す方法です。