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.
次のコード:
trait T { function foo() {} } class C { use T { T::foo as bar; } use T { T::foo as baz; } }
次のエラーが発生します。
Cで他の特性メソッドとの衝突があるため、特性メソッドバーは適用されていません。
クラスでトレイトを2回使用することは可能ですか?
トレイトで異なる名前で複数回定義されたメソッドを「インポート」するには、次のようにします。
class C { use T { foo as bar; foo as baz; } }
はい、トレイトを2回使用できます。
trait T { function foo() {} } class C { use T { T::foo as bar; T::foo as baz; } }