<?php class father{ //定义father类 //定义public描述的成员属性和方法 public $eyes=2; public $ears=2; public function walk(){ echo '走路。'; } } class son extends father{ //定义son类并且继承自father类 } $father=new father(); //实例化一个father类的对象 //访问father类的属性和方法 echo "father有{$father->eyes}个眼睛,有{$father->ears}个耳朵并且father会"; $father->walk(); $son=new son(); //实例化son类的对象 //访问son类的属性和方法 echo "<br />son有{$son->eyes}个眼睛,有{$son->ears}个耳朵并且son会"; $son->walk(); ?>