The example in this article describes the usage of the final keyword in php. It is mainly explained to you in the form of code and shared with you for your reference. The details are as follows:
The final keyword can only be used to define classes and define methods.
Classes marked with the final keyword cannot be inherited
final class Person{ ....... } class Student extends Person{ ....... }
An error message will appear. Fatal error: Class Student may not inherit from final class (Person)
Methods marked with the final keyword cannot be overridden by subclasses
class Person{ final function Say(){ ...... } } class Student extends Person{ function Say(){ ...... } }
The following error will occur:
Fatal Error: Cannot Override final method Person::say()
Related recommendations:
php object-oriented final keyword usage and examples
The above is the detailed content of How to use the final keyword in Guantu in PHP. For more information, please follow other related articles on the PHP Chinese website!