Created
September 20, 2020 11:46
-
-
Save ricardoaugusto/39e49497925f6dd286f2fa4a69d0125f to your computer and use it in GitHub Desktop.
Trait Method Collision Workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| trait TraitA { | |
| public function show() { | |
| return 123; | |
| } | |
| } | |
| trait TraitB { | |
| public function show() { | |
| return 765; | |
| } | |
| } | |
| class MethodCollision { | |
| public function showA() { | |
| $traitA = new class { use TraitA; }; | |
| echo $traitA->show(); | |
| } | |
| public function showB() { | |
| $traitB = new class { use TraitB; }; | |
| echo $traitB->show(); | |
| } | |
| } | |
| (new MethodCollision())->showA(); | |
| (new MethodCollision())->showB(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment