PHP5中使用parent::来引用父类的方法。
- parent:: 可用于调用父类中定义的成员方法。
- parent::的追溯不仅于直接父类。
通过parent::调用父类方法
<!-- 声明一个员工类,经理类继承自员工类 --> <? class employee{ protected $sal=3000; public function getSal(){ $this->sal = $this->sal + 1200; return $this->sal ; } } class Manager extends employee { //如果想让经理在员工工资的基础上多发1500元. //必须先调用父类的getSal()方法. public function getSal(){ parent::getSal();// 这里调用了父类的方法. $this->sal = $this->sal + 1500; return $this->sal ; } } $emp = new employee(); echo "普通员工的工资是 " . $emp->getSal(); echo "<br>"; $manager = new Manager(); echo "经理的工资是: " . $manager->getSal(); ?>