(PHP 5)
ReflectionMethod::invoke — Invoke
Invokes a reflected method.
The object to invoke the method on. In case of static methods, you can pass null to this parameter.
Zero or more parameters to be passed to the method. It accepts a variable number of parameters which are passed to the method.
Returns the method result.
A ReflectionException if the object parameter does not contain an instance of the class that this method was declared in.
A ReflectionException if the method invocation failed.
Beispiel #1 ReflectionMethod::invoke() example
<?php
class HelloWorld {
public function sayHelloTo($name) {
return 'Hello ' . $name;
}
}
$reflectionMethod = new ReflectionMethod('HelloWorld', 'sayHelloTo');
echo $reflectionMethod->invoke(new HelloWorld(), 'Mike');
?>
Das oben gezeigte Beispiel erzeugt folgende Ausgabe:
Hello Mike