In PHP, the final keyword can be used to mark a class or method as "final", which means that it cannot be extended or overridden by any subclass.
A final class is a class that cannot be subclassed. In other words, it is a class that cannot have any child classes. Once a class is marked as final, no other class can extend it or inherit from it. This is often used to prevent further modification or extension of a class that is intended to be a "leaf" class in a class hierarchy.
1 2 3 | final class MyFinalClass { // Class implementation goes here } |
1 2 3 4 5 6 7 8 9 10 11 | class MyBaseClass { final public function myFinalMethod() { // Method implementation goes here } } class MySubclass extends MyBaseClass { // This code will generate a fatal error, because myFinalMethod is marked as final in MyBaseClass public function myFinalMethod() { // Method implementation goes here } } |