classtest{private$a=array();publicfunction__construct(){$this->geta();}privatefunctiongeta(){$b[]=1;$b[]=2;$this->a=$b;//沒有return}}//反射獲取$ref_class=newReflectionClass('test');$geta=$ref_class->newInstance();$method=$ref_class->getmethod('geta');$method->setAccessible(true);$a=$method->invoke($rongyuclass);//空的,因為geta不返回任何值有這樣的一個類,現在里面的私有方法geta沒有return出任何數據,但是構造方法那邊給私有屬性a賦值,我直接用反射去取變量$a的時候得到的只能是空值,如何先執(zhí)行構造,然后得到賦值后的私有屬性a?
php反射類如何獲取構造方法得到的私有屬性
四季花海
2019-05-21 17:16:03