Advertisement
CosminVarlan

PHP_introspection_adaugare_functie

Mar 24th, 2020
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. <?php
  2. class Exemplu
  3. {
  4.     public function __call($functie, $parametri)
  5.     {
  6.         if (isset($this->$functie)) {
  7.             return call_user_func_array($this->$functie, $parametri);
  8.         }
  9.     }
  10.    
  11.     // dupa ce ati verificat codul, incercati sa scoateti comentariul de pe functia urmatoare
  12.     // si sa vedeti ce se intampla:
  13.     /*
  14.     public function functie_la_runtime(){
  15.         echo "deja exist";
  16.     }
  17.     */
  18. }
  19.  
  20. $ex = new Exemplu();
  21. $reflection = new ReflectionClass("Exemplu");
  22. $metode = $reflection->getMethods();
  23.  
  24. if (!$reflection->hasMethod("functie_la_runtime"))
  25. {
  26.     $ex->functie_la_runtime = function () {
  27.                             echo "Functie adaugata la runtime.<br />";
  28.                         };
  29. }  
  30. $ex->functie_la_runtime();
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement