<?php /** * Created by PhpStorm. * User: admin * Date: 2016/7/18 * Time: 9:41 */ //通过继承实现多态 class father{ public $name; public function getWeight(){ return"59kg"; } public function setName(){ $this->name="father";//this 调用本身 } } class son extends father{ public function setName() { // parent::setName(); // TODO: Change the autogenerated stub $this->name="son"; } } //上段注释,输出father。 class son1 extends father{ public function getWeight() { return parent::getWeight(); // TODO: Change the autogenerated stub } } $son=new son(); $son->setName(); echo $son->name."<br>"; $weight=new son1(); $weight->getWeight(); echo $weight->getWeight();