Final keyword in PHP is used in different context. The final keyword is used only for methods and classes.
Final methods: When a method is declared as final then overriding on that method can not be performed. Methods are declared as final due to some design reasons. Method should not be overridden due to security or any other reasons.
Base class final printdata function Derived class non final function
Final Classes: A class declared as final can not be extended in future. Classes are declared as final due to some design level issue. Creator of class declare that class as final if he want that class should not be inherited due to some security or other reasons. A final class can contain final as well as non final methods. But there is no use of final methods in class when class is itself declared as final because inheritance is not possible.
final base class final method non final method of final base class
Note: Unlike Java final keyword in PHP can only be used for methods and classes not for variables.
- PHP | var keyword
- CSS | currentcolor keyword
- Python in Keyword
- CSS | unset keyword
- ES6 | Void Keyword
- CSS | revert keyword
- Difference between revert and unset keyword in CSS
- Difference between private keyword and private fields in TypeScript
- How to Create an Image Overlay Icon using HTML and CSS ?
- How to Vertically Align Text Next to an Image using CSS ?
- How to Create ToDo App using ReactJS ?
- How to Remove URL from Printing the Page ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.