<html>
<body>
abstract class ParentClass {
// 带有参数的抽象方法
abstract protected function prefixName($name);
}
class ChildClass extends ParentClass {
public function prefixName($name) {
if ($name == "Bill Gates") {
$prefix = "Mr.";
} elseif ($name == "Jane Doe") {
$prefix = "Mrs.";
} else {
$prefix = "";
}
return "{$prefix} {$name}";
}
}
$class = new ChildClass;
echo $class->prefixName("Bill Gates");
echo "<br>";
echo $class->prefixName("Jane Doe");
</body>
</html>