x
 
<!DOCTYPE html>
<html>
<body>
<?php
// 父类
abstract class Car {
  public $name;
  public function __construct($name) {
    $this->name = $name;
  }
  abstract public function intro() : string; 
}
// 子类
class Audi extends Car {
  public function intro() : string {
    return "选择德国品质!我是一辆 $this->name!"; 
  }
}
class Volvo extends Car {
  public function intro() : string {
    return "以中国为荣!我是一辆 $this->name!"; 
  }
}
class Citroen extends Car {
  public function intro() : string {
    return "法国奢华!我是一辆 $this->name!"; 
  }
}
// 从子类创建对象
$audi = new audi("奥迪");
echo $audi->intro();
echo "<br>";
$volvo = new volvo("比亚迪");
echo $volvo->intro();
echo "<br>";
$citroen = new citroen("雪铁龙");
echo $citroen->intro();
?>
 
</body>
</html>