PHP 反射 reflection

PHP 反射 reflection

反射一个类

//反射一个类
$obj = new \App\DataProviders\RightScale(['cloud'=>3,'deployment'=>'']);
$observer = new \ReflectionClass($obj);

//反射一个属性
$property = $observer->getProperty('_instance');
$property->setAccessible(true);
$property->setValue($obj,'DHP9CG78PUVFA');

//反射一个方法
$method = $observer->getMethod('getCpuUsage');
$method->setAccessible(true);
$re = $method->invoke($obj, []);