PHP Reflection class carries parameters to execute the reflection object method to pass in parameter function example parsing. Background: for the before after and controller and action functions in the early kohana framework, you can use the reflection class to flexibly execute the functions in the specified sequence. if an exception occurs during execution, you can capture the output through the exception capture provided by PHP, which involves the problem of passing the parameters of the class object. how can you transmit multiple parameters or even reference parameters to the functions in the reflection class, this PHP also provides the ReflectionMethod: invokeArgs passed by the function in the corresponding reflection class.
The code snippet is as follows:
$ Class = new ReflectionClass ('person '); // creates a reflection class for the Person class $ instance = $ class-> newInstanceArgs ($ args ); // It is equivalent to instantiating the Person class public stdclass newInstance (mixed * args) // test whether the input object is an instance of this class
Refer to more reflection articles:
Http://flandycheng.blog.51cto.com/855176/326021/
Http://www.phperz.com/article/14/0809/17371.html
Research by myself: http://justwinit.cn/post/2090/
ReflectionMethod: invokeArgs
(PHP 5> = 5.1.0)
ReflectionMethod: invokeArgs-execution with parameters
Description
Public mixed ReflectionMethod: invokeArgs (object $ object, array $ args)
Use arrays to send parameters to methods and execute them.
Parameters
Object
The object that calls the method. if it is a static object, set it to null.
Args
The method parameters transmitted using array.
Return value
Return method return value
Error/exception
If the instance specified by the object cannot execute the method, a ReflectionException is generated.
If the method call fails, a ReflectionException is generated.
Example
Example #1 ReflectionMethod: invokeArgs () example
Class HelloWorld {
Public function sayHelloTo ($ name ){
Return 'hello'. $ name;
}
}
$ ReflectionMethod = new ReflectionMethod ('helloworld', 'sayhelloto ');
Echo $ reflectionMethod-> invokeArgs (new HelloWorld (), array ('Mike '));
?>
The above routine will output:
Hello Mike
Note
Note:
If a function has parameters that need to be referenced, they must be passed in as references.
See
ReflectionMethod: invoke ()-Invoke
_ Invoke ()
Call_user_func_array ()-Call the callback function and use an array parameter as the callback function parameter.
From: http://help.bitscn.com/php/reflectionmethod.invokeargs.html