PHP面向对象程序设计OOP继承用法入门示例

前端之家收集整理的这篇文章主要介绍了PHP面向对象程序设计OOP继承用法入门示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了PHP面向对象程序设计OOP继承用法分享给大家供大家参考,具体如下:

PHP;"> name = $name; $this->sex = $sex; $this->age = $age; } function say() { echo $this->name . "在说话
"; } function run() { echo "在走路·
"; } } class Student extends Person { var $school; function __construct($name = "",$age = 22,$school="") { parent::__construct($name,$sex,$age); $this->school = $school; } function study() { echo $this->name."正在".$this->school."学习
"; } } class Teacher extends Student { var $wage; function teaching() { echo $this->name."正在".$this->school."教学,每月工资为".$this->wage."
"; } } $teacher1 = new Teacher("kaifu","男",22); $teacher1->school = "edu"; $teacher1->wage = 4000; $teacher1->say(); $teacher1->study(); $teacher1->teaching(); ?>

结果:

PHP;"> kaifu在说话 kaifu正在edu学习 kaifu正在edu教学,每月工资为4000

更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》、《》及《

希望本文所述对大家PHP程序设计有所帮助。

猜你在找的PHP相关文章