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 https://verraes.net/2014/05/final-classes-in-php/, https://app.daily.dev/posts/how-to-mock-final-classes-in-phpunit-thl2afemj
Related : Overwrite, Private Visibility, Abstract Class, Abstract Keyword, Static Constant, Final Class Constants, Fluent Interface, Object, Protected Visibility, Public Visibility
Added in PHP 7.0