第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

php反射類如何獲取構造方法得到的私有屬性

php反射類如何獲取構造方法得到的私有屬性

四季花海 2019-05-21 17:16:03
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?
查看完整描述

2 回答

?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

$ref=newReflectionClass('test');$a=$ref->getProperty('a');$a->setAccessible(true);//設置屬性a的訪問權限var_dump($a->getValue(newtest));
                            
查看完整回答
反對 回復 2019-05-21
?
瀟瀟雨雨

TA貢獻1833條經驗 獲得超4個贊

classtest{
private$a=array();
publicfunction__construct(){
$this->geta();
}
privatefunctiongeta(){
$b[]=1;
$b[]=2;
$this->a=$b;
//沒有return
}
}
$test=newtest;
$closure=function(){
return$this->a;
};
//rebindstheclosuretothe$testobject
$closure=$closure->bindTo($test,$test);
print_r($closure());
                            
查看完整回答
反對 回復 2019-05-21
  • 2 回答
  • 0 關注
  • 578 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號