Final Keyword¶
The final keyword prevents child classes from overriding a method or a constant by prefixing the definition with final.
The final keyword cannot be used with the private keyword: a private method is not visible in the child classes, and can’t also be redefined.
<?php
class x {
final const X = 1;
final function method() { }
}
?>
See also Final Classes: Open for Extension, Closed for Inheritance, How to Mock Final Classes in PHPUnit, Why (nearly) every PHP class you write should be abstract or final and When to declare classes final.
Related : Overwrite, Private Visibility, Abstract Class, Abstract Keyword, Static Constant, Final Class Constants, Fluent Interface, Object, Protected Visibility, Public Visibility, Abstract Method, Concrete Method, Var
Added in PHP 7.0