This article mainly introduces the use of final keywords in php, and analyzes the functions, usage, and precautions of final keywords in the form of instances, for more information about the final keyword usage in php, see the example in this article. We will share this with you for your reference. The details are as follows:
Final keywords 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 is displayed. Fatal error: Class Student may not inherit from final class (Person)
The method marked with the final keyword cannot be overwritten by the quilt class.
Class Person {final function Say () {...} class Student extends Person {function Say (){......}}
The following error occurs:
Fatal Error: Cannot Override final method Person: say ()
The above is the final keyword usage analysis content in php. for more related articles, please follow the PHP Chinese network (www.php1.cn )!