Exemplo n.º 1
0
 /**
  * Calls a function using the python keyword emulation of func_get_call_args()
  */
 public static function call($name, $args, $ignoreUnknown = false)
 {
     if (is_array($name)) {
         $rc = new \ReflectionClass($name[0]);
         $func = $rc->getMethod($name[1]);
     } elseif (!$name instanceof \ReflectionFunction) {
         $func = new \ReflectionFunction($name);
     }
     if (!$func instanceof \ReflectionFunctionAbstract) {
         throw new \InvalidArgumentException();
     }
     $callArgs = func_get_call_args($func, $args, $ignoreUnknown);
     return call_user_func_array($name, $callArgs);
 }
Exemplo n.º 2
0
 /**
  * This supports Python's style of args followed by keyword args:
  * $yourInstance->call('yourMethod', [$first, $second, 'fourth'=>$fourth, 'third'=>$third]);
  */
 public static function callStatic($method, $args = [])
 {
     $class = new \ReflectionClass(get_called_class());
     $method = $class->getMethod($method);
     return $method->invokeArgs(null, func_get_call_args($method, $args));
 }