14 反射
暂时写点代码看着,以后再来深入了解。
class Cat{
public $name;
public $food;
public function __construct($name,$food){
$this->name = $name;
$this->food = $food;
}
public function scream($sound){
echo $this->name . '喜欢吃' . $this->food . '' . $sound;
}
}
//1.创建ReflectionClass对象
$reflect_obj = new ReflectionClass('Cat');
//2.创建一个Cat对象实例
$cat = $reflect_obj->newInstance('小猫','鱼');
//3.得到反射方法speak
$reflect_method_scream = $reflect_obj->getMethod('scream');
//4.通过反射方法代理调用speak
$reflect_method_scream->invoke($cat,'嗷嗷叫');

浙公网安备 33010602011771号