Prevent inheritance of a class using the final
keyword:
<?php
final class MyClass {
public $name = "John";
}
// This code will throw an error
class AnotherClass extends MyClass{};
?>
The final
keyword is used to prevent a class from being inherited and to prevent inherited method from being overridden.
Read more about inheritance in our PHP OOP - Inheritance Tutorial.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!