This article mainly introduces the usage of the final keyword in php, and analyzes the function, usage and related precautions of the final keyword in the form of examples. Friends in need can refer to the following
The examples in this article describe Usage of 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 define methods.
Classes marked with the final keyword cannot be inherited
final class Person{ ....... } class Student extends Person{ ....... }
An error will occur hint. 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()
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
PHP interface implementation of drag-and-drop sorting function example
PHPMethod to change the array key value
The above is the detailed content of Detailed explanation of the usage of final keyword in php. For more information, please follow other related articles on the PHP Chinese website!