1.反射有什么浸染
反射可以用作文档天生。 反射可以做hook插件功能或者动态代理
通过反射我们可以得到一个类的干系属性:

常量 Contants 属性 Property Names 方法 Method Names静态 属性 Static Properties 命名空间 Namespace Person类是否为final或者abstract
2.如何利用反射
2.1得到反射
如下有一个大略的Person类
<!--?php
class Person {
protected $name ;
protected $age;
public function getName() {
return $this--->name;
}
public static function getAge() {
return $this->age;
}
}
我们只须要把类名’Person’传给ReflectionClass即可得到Person的反射。
$class = new ReflectionClass('Person');
$instance = $class->newInstanceArgs();
2.2获取属性
$properties = $class->getProperties();
foreach( $properties as $pro ) {
echo $pro->getName().\公众\n\公众;
}
输出如下:
2.3获取方法
$method = $class->getMethods();
var_dump($method);
输出如下:
2.4实行类的方法
$getName = $method[0];
$getName->invoke($instance);
//或者
$instance->getName();
上述就可以实行类中的方法。