Guest User

Untitled

a guest
Jul 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. /**
  2. * Invoke method by using reflection.
  3. * Require PHP5 (>= 5.3.2)
  4. * @param $method_name
  5. * @param $obj - An object that invokes the method.
  6. * @param mothod_args... Arguments for the method.
  7. */
  8. public static function invoke_method($method_name, $obj) {
  9. $class_name = get_class($obj);
  10. $class = new ReflectionClass($class_name);
  11. $method = $class->getMethod($method_name);
  12. $method->setAccessible(true);
  13.  
  14. $mothod_args = func_get_args();
  15. array_shift($mothod_args);
  16. array_shift($mothod_args);
  17.  
  18. return $method->invokeArgs($obj, $mothod_args);
  19. }
Add Comment
Please, Sign In to add comment