Source Code:
(back to article)
<?php // Example 1 trait TraitA { function someMethod() { echo "This is from TraitA."; } } trait TraitB { function someMethod() { echo "This is from TraitB."; } } class MyClass { use TraitA, TraitB { TraitA::someMethod insteadof TraitB; } } $obj = new MyClass(); $obj->someMethod(); // Output: This is from TraitA. // Example 2 trait TraitC { function someMethod() { echo "This is from TraitC."; } } trait TraitD { function someMethod() { echo "This is from TraitD."; } } trait TraitE { function someMethod() { echo "This is from TraitE."; } } class MyOtherClass { use TraitC, TraitD, TraitE { TraitC::someMethod insteadof TraitD, TraitE; } } $obj2 = new MyOtherClass(); $obj2->someMethod(); // Output: This is from TraitC.
Result:
Report an issue