<?php header("Content-Type:text/html;charset=utf-8;"); class car { public $pingpai; public $price; function __construct($pingpai, $price) { $this->pingpai = $pingpai; $this->price = $price; } function showCommon() { return "common"; } } class BMW extends car { function showCar() { return "我买了一辆:" . $this->pingpai . ",它花了我" . $this->price . "钱"; } } $bmw = new BMW("宝马", "50w"); $show = $bmw->showCar(); var_dump($show); var_dump($bmw->showCommon());