Home >Backend Development >PHP Tutorial >Reflection usage example of PHP class

Reflection usage example of PHP class

高洛峰
高洛峰Original
2016-12-23 12:51:321137browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn