Reflection usage example of PHP class

高洛峰
Release: 2023-03-04 07:38:01
Original
1132 people have browsed it

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);
    }
}
Copy after login

For more articles related to examples of reflection usage in PHP classes, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template