您好,登錄后才能下訂單哦!
這篇文章主要介紹PHP面向?qū)ο蟪绦蛟O(shè)計(jì)OOP繼承怎么用,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
具體如下:
<?php class Person { var $name;//protected var $sex; var $age; function __construct($name = "", $sex = "男", $age = 22) { $this->name = $name; $this->sex = $sex; $this->age = $age; } function say() { echo $this->name . "在說話<br/>"; } function run() { echo "在走路·<br/>"; } } class Student extends Person { var $school; function __construct($name = "", $sex = "男", $age = 22,$school="") { parent::__construct($name,$sex,$age); $this->school = $school; } function study() { echo $this->name."正在".$this->school."學(xué)習(xí)<br/>"; } } class Teacher extends Student { var $wage; function teaching() { echo $this->name."正在".$this->school."教學(xué),每月工資為".$this->wage."<br/>"; } } $teacher1 = new Teacher("kaifu","男",22); $teacher1->school = "edu"; $teacher1->wage = 4000; $teacher1->say(); $teacher1->study(); $teacher1->teaching(); ?>
結(jié)果:
kaifu在說話 kaifu正在edu學(xué)習(xí) kaifu正在edu教學(xué),每月工資為4000
以上是“PHP面向?qū)ο蟪绦蛟O(shè)計(jì)OOP繼承怎么用”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。