💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## final 关键字 如果父类中的方法被声明为 `final`,则子类无法覆盖该方法。如果一个类被声明为 `final`,则不能被继承。 父类方法被声明为 `final`: ``` <?php class BaseClass { public function test() { echo "BaseClass::test() called." . PHP_EOL; } final public function moreTesting() { echo "BaseClass::moreTesting() called." . PHP_EOL; } } class ChildClass extends BaseClass { public function moreTesting() { echo "ChildClass::moreTesting() called." . PHP_EOL; } } // Results in Fatal error: Cannot override final method BaseClass::moreTesting() ?> ``` 父类被声明为 `final`: ``` <?php final class BaseClass { public function test() { echo "BaseClass::test() called." . PHP_EOL; } public public function moreTesting() { echo "BaseClass::moreTesting() called." . PHP_EOL; } } class ChildClass extends BaseClass { } // Fatal error: Class ChildClass may not inherit from final class (BaseClass) ?> ```