亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

有沒有人遇到過這個問題哈!php中繼承Static與延遲綁定

有沒有人遇到過這個問題哈!php中繼承Static與延遲綁定

慕婉清6462132 2019-10-16 16:50:06
題目描述題目來源及自己的思路輸出Parent:parent_only=fromchild,both_distinct=fromparentChild:parent_only=fromchild,both_distinct=fromchild,child_only=fromchildhttps://www.php.net/manual/zh...相關代碼//請把代碼文本粘貼到下方(請勿用圖片代替代碼)$a=newstaticparent;var_dump(get_class_vars("staticparent"));$a=newstaticchild;echo"";var_dump(get_class_vars("staticparent"));出現以下結果array(2){["parent_only"]=>string(10)"fromparent"["both_distinct"]=>string(10)"fromparent"}array(2){["parent_only"]=>string(9)"fromchild"["both_distinct"]=>string(10)"fromparent"}我想咨詢下,為什么newstaticchild后父類的parent_only會被修改,而both_distinct卻不會.另外輸出的原因是什么,而且把注釋里面self::打開,替換static,結果為何是一致Parent:parent_only=fromchild,both_distinct=fromparentChild:parent_only=fromchild,both_distinct=fromchild,child_only=fromchild
查看完整描述

2 回答

?
慕萊塢森

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

因為被覆蓋了啊staticchild沒有$parent_only,所以staticchild::$parent_only調用的是staticparent的$parent_only而staticparent的$parent_only被設置了fromchild所以打印出了fromchild
另外靜態綁定不是這么用的。
子類繼承父類覆蓋了a屬性。當子類的一個實例對象調用父類一個獲取或使用a屬性方法時,一般情況下,使用的是父類的a屬性。而靜態綁定,則使用的是子類自身的a屬性。概況起來就是誰的對象用誰的
                            
查看完整回答
反對 回復 2019-10-16
?
千萬里不及你

TA貢獻1784條經驗 獲得超9個贊

本來寫了一些,但是感覺我自己都要被轉暈了,可以參考這篇文章。
(PHP)Latestaticbindingandchildattributedeclaration-Blog-(BKcore)ThibautDespoulain
                            
查看完整回答
反對 回復 2019-10-16
  • 2 回答
  • 0 關注
  • 203 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

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

公眾號

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