What is a PHP reflection class, as the name implies, can be understood as a mapping of a class.
To give a sample example:
Class Fuc {//define one of the classes
static function EC () {
Echo' I am a class ';
}
}
$class =new reflectionclass (' fuc '); Set up a reflection class for the Fuc class
Echo $class; Output this reflection class
class [ class A] {@@ f:\phpweb\myphp\test.php 23-30-constants [0] {}-static properties [0] {}-static Methods [0] {}-Properties [0] {}-Methods [1] {method [public Method __construct] {@@ f:\phpweb\myph p\test.php 26-29} }}
$FUC = $class->newinstance ();//equivalent to instantiating the FUC class
$fuc->ec ();//method of running FUC EC
/* Final output: I am a class */
Some of the more advanced ways to use
$ec = $class->getmethod (' EC ');//Get the EC method in the Fuc class
$FUC = $class->newinstance ();//Instantiation
$ec->invoke ($FUC);//Run EC method
The above process is very familiar. In fact, similar to the method of invoking an object
Just here is the reverse, method in front, object in the back
Example
TRY{//assumes the class if the controller name exists (class_exists ($this->getcontroller ())) {//using the Reflection API to construct a controller class corresponding to the Reflection class $RC = new Reflectionclass ($ This->getcontroller ());//Assume that the class implements the IController interface if ($RC->implementsinterface (' IController ')) {// The class has a parsed action string that points to the method name if ($RC->hasmethod ($this->getaction ())) {//constructs an instance of a controller class $controller = $RC Newinstance ();//Gets the method object that the class $action the pointer to $method = $RC->getmethod ($this->getaction ());//Reflection class Method Object Invocation method: $method- >invoke ($controller);} else {//below for possible throw exception throw new Exception ("Action");}} else {throw new Exception ("Interface");}} else {throw new Exception ("Controller");} } catch (Exception $e) { echo $e; }
PHP Reflection Class Reflectionclass