x
 
<!DOCTYPE html>
<html>
<body>
<?php
abstract class ParentClass {
  // 带有参数的抽象方法
  abstract protected function prefixName($name);
}
class ChildClass extends ParentClass {
  // 子类可以定义父类抽象方法中未包含的可选参数
  public function prefixName($name, $separator = ".", $greet = "Dear") {
    if ($name == "Bill Gates") {
      $prefix = "Mr";
    } elseif ($name == "Jane Doe") {
      $prefix = "Mrs";
    } else {
      $prefix = "";
    }
    return "{$greet} {$prefix}{$separator} {$name}";
  }
}
$class = new ChildClass;
echo $class->prefixName("Bill Gates");
echo "<br>";  
echo $class->prefixName("Jane Doe");
?>
 
</body>
</html>