這篇文章主要介紹了PHP物件導向程式設計OOP繼承用法,結合簡單實例形式分析了php類別的定義與繼承使用方法,需要的朋友可以參考下
本文實例講述了PHP物件導向程式設計OOP繼承用法。分享給大家供大家參考,具體如下:
<?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."学习<br/>"; } } class Teacher extends Student { var $wage; function teaching() { echo $this->name."正在".$this->school."教学,每月工资为".$this->wage."<br/>"; } } $teacher1 = new Teacher("kaifu","男",22); $teacher1->school = "edu"; $teacher1->wage = 4000; $teacher1->say(); $teacher1->study(); $teacher1->teaching(); ?>
# 成果:
以上就是本文的全部內容,希望對大家的學習有所幫助。PHP擷取類別snoopy實例介紹
php使用snoopy與curl模擬登陸的實例分享
####
以上是PHP物件導向程式設計OOP繼承用法詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!