Examples of Reflection Usage of the PHP Class
- 2021-07-24 10:24:10
- OfStack
This article illustrates the reflection usage of PHP class. Share it for your reference. The specific implementation method is as follows:
This example implements getting 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) { // If it is a legal class name
// Get reflection class
$class = new ReflectionClass($className);
// Get the method of the class
$recd = $class->getmethod('exeRecd');
// Generate an instance of a class
$instance = $class->newInstance($this->qq, $this->ip);
// Method of execution
$result[$ch] = $recd->invoke($instance);
}
}
I hope this article is helpful to everyone's PHP programming.