使用关键字 extends
<?php class person{ var $name; var $sex; var $age; function __construct($name='',$sex='男',$age=1){ $this->name=$name; $this->age=$age; $this->sex=$sex; } function say(){ echo '我的名字:',$this->name,'我的性别是',$this->sex,'我的年龄是',$this->age; echo '<br>'; } function run(){ echo $this->name,'正在走路'; echo '<br>'; } } class stu extends person{ var $school; function study(){ echo $this->name,'正在',$this->school,'学习'; echo '<br>'; } } class teacher extends stu{ var $wage; function teaching(){ echo $this->name,'正在',$this->school,'教书','每月工资是',$this->wage; } } $teacher1= new teacher('张三','男',40); $teacher1->school='edu'; $teacher1->wage=5000; $teacher1->say(); $teacher1->run(); $teacher1->teaching(); /* 打印结果是: 我的名字:张三我的性别是男我的年龄是40 张三正在走路 张三正在edu教书每月工资是5000 */ ?>