class test{
private $a=array();
public function __construct() {
$this->geta ();
}
private function geta(){
$b [] = 1;
$b [] = 2;
$this->a = $b;
// 沒(méi)有return
}
}
//反射獲取
$ref_class = new ReflectionClass('test');
$geta= $ref_class->newInstance();
$method = $ref_class->getmethod('geta');
$method->setAccessible(true);
$a = $method->invoke($rongyuclass); //空的,因?yàn)間eta不返回任何值
有這樣的一個(gè)類,現(xiàn)在里面的私有方法geta沒(méi)有return出任何數(shù)據(jù),但是構(gòu)造方法那邊給私有屬性a賦值,我直接用反射去取變量$a的時(shí)候得到的只能是空值,如何先執(zhí)行構(gòu)造,然后得到賦值后的私有屬性a?
php反射類如何獲取構(gòu)造方法得到的私有屬性
慕工程0101907
2019-03-18 15:24:13