Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. <?php
  2.  
  3. function isCallable($obj, $method)
  4. {
  5. //$test1 = method_exists($obj, $method);
  6. //var_dump($test1);
  7. //TRUE
  8.  
  9. //$test2 = is_callable([$obj, $method]);
  10. //var_dump($test2);
  11. //FALSE
  12.  
  13. return (method_exists($obj, $method) && is_callable([$obj, $method]));
  14. }
  15.  
  16. trait helper
  17. {
  18. public function show()
  19. {
  20. echo "show!";
  21.  
  22. if(isCallable($this, "afterShow"))
  23. {
  24. $this->afterShow();
  25. }
  26.  
  27. //$this->afterShow();
  28.  
  29. }
  30. }
  31.  
  32. class my_class
  33. {
  34. use helper;
  35.  
  36. private function afterShow()
  37. {
  38. echo "...then this.";
  39. }
  40. }
  41.  
  42. $objMyClass = new my_class();
  43.  
  44. $objMyClass->show();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement