Trait_Stuff - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Trait_Stuff.php

  1. <?php
  2.  
  3.         trait A {
  4.     public function smallTalk() {
  5.         echo 'You are executing smallTalk in TRAIT "A" with lowercase "a" ';
  6.     }
  7.     public function bigTalk() {
  8.         echo 'You are executing BIgTalk in TRAIT "A" with UPPERCASE "A" ';
  9.     }
  10. }
  11.  
  12. trait B {
  13.     public function smallTalk() {
  14.         echo ' You are executing smallTalk in TRAIT "B" with lowercase "b" '; 
  15.     }
  16.     public function bigTalk() {
  17.          echo ' You are executing BIGTALK in TRAIT "B" with UPPERCASE "B" '; 
  18.     }
  19. }
  20.  
  21. class Talker {
  22.     use A, B {
  23.         B::smallTalk insteadof A;
  24.         A::bigTalk insteadof B;
  25.     }
  26. }
  27.  
  28. class Aliased_Talker {
  29.     use A, B {
  30.         B::smallTalk insteadof A;
  31.         A::bigTalk insteadof B;
  32.         B::bigTalk as talk;
  33.     }
  34. }
  35.  
  36. $talk = new Talker();
  37. echo $talk->smallTalk();
  38.  
File Description
  • Trait_Stuff
  • PHP Code
  • 17 Jul-2021
  • 792 Bytes
You can Share it: