Advertisement
Yousuf1791

trait

Jun 17th, 2023
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.36 KB | None | 0 0
  1. <?php
  2.  
  3. trait hello{
  4.     public function say_hello(){
  5.         echo "Hello world";
  6.     }
  7. }
  8.  
  9. trait bye{
  10.     public function say_bye(){
  11.         echo "Bye everyone";
  12.     }
  13. }
  14.  
  15. class base{
  16.     use hello;
  17.     use bye;
  18. }
  19.  
  20. class base2{
  21.     use hello;
  22. }
  23.  
  24. $obj = new base();
  25. $obj2 = new base();
  26.  
  27. $obj->say_hello();
  28. echo "<br>";
  29. $obj->say_bye();
  30. echo "<br>";
  31. $obj2->say_hello();
  32.  
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement