This article introduces the content of "PHP class and object" Final keyword, has a certain reference value, now share to everyone, the need for friends can refer to
Final keyword
To be declared Final:
1. Class, cannot be inherited. 2. Methods, can not cover the quilt class. 3. Attributes, constants, cannot be defined as Final
Example #1 Final Method Example <?phpclass baseclass {public function test () { echo "baseclass::test () called\n"; } Final public Function moretesting () { echo "baseclass::moretesting () called\n"; }} Class ChildClass extends BaseClass {public function moretesting () { echo "childclass::moretesting () called\n"; }} Results in Fatal error:cannot override final Method baseclass::moretesting ()?>
example #2 Final Class Example <?phpfinal class BaseClass {public function test () { echo "Baseclass::test () called\n"; }//Whether or not you declare the method as final, there is no relation to the final public function moretesting () {echo "baseclass::moretesting () called\n"; }}class ChildClass extends BaseClass {}//generate Fatal Error:class ChildClass may not inherit from final Class (BaseClass)? & gt;