構(gòu)造函數(shù) 與java不同的,php類的構(gòu)造函數(shù)用__construct()函數(shù)表示
對(duì)該函數(shù)的學(xué)習(xí)參照了以下博文: php面向?qū)ο缶幊讨畼?gòu)造方法__construct() 下面是練習(xí)代碼:
run結(jié)果: 
注意 1. 在同一個(gè)類中只能聲明一個(gè)構(gòu)造函數(shù),原因是,PHP不支持構(gòu)造函數(shù)重載。 2. 構(gòu)造函數(shù)名稱是以兩個(gè)下畫(huà)線開(kāi)始的__construct() 3. 對(duì)類中顯示或隱式聲明的__construct()構(gòu)造函數(shù),在調(diào)用該構(gòu)造函數(shù)時(shí),若實(shí)參中無(wú)參數(shù),則運(yùn)行原構(gòu)造函數(shù);若有帶實(shí)參,則以實(shí)參與構(gòu)造函數(shù)中形參的對(duì)應(yīng)關(guān)系,相應(yīng)替換輸出。
新聞熱點(diǎn)
疑難解答
網(wǎng)友關(guān)注