Home >Backend Development >PHP Tutorial >Reflection usage example of PHP class
The examples in this article describe the use of reflection in PHP classes. Share it with everyone for your reference. The specific implementation method is as follows:
This example implements obtaining the corresponding class for each channel to perform the corresponding operation. The details are as follows:
foreach($this->chs as $ch) { $className = $this->chsMap[$ch]; if($className) { // 如果是合法的类名 // 获取反射类 $class = new ReflectionClass($className); // 获取类的方法 $recd = $class->getmethod('exeRecd'); // 生成类的实例 $instance = $class->newInstance($this->qq, $this->ip); // 执行方法 $result[$ch] = $recd->invoke($instance); } }
For more articles related to examples of reflection usage in PHP classes, please pay attention to the PHP Chinese website!