Home >Backend Development >PHP Tutorial >Analysis on usage of final keyword in php
The example in this article describes the usage of the final keyword in php. Share it with everyone for your reference, the details are as follows:
The final keyword can only be used to define classes and 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 appear:
Fatal Error: Cannot Override final method Person::say()
The above is the analysis of the usage of final keyword in PHP. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!