|
Final KeywordPHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended. Example 10.29. Final methods example<?php Example 10.30. Final class example<?php Code Examples / Notes » language.oop5.finalliumr
this key word can describe a class or a class member function
penartur
Note that you cannot ovverride final methods even if they are defined as private in parent class. Thus, the following example: <?php class parentClass { final private function someMethod() { } } class childClass extends parentClass { private function someMethod() { } } ?> dies with error "Fatal error: Cannot override final method parentClass::someMethod() in ***.php on line 7" Such behaviour looks slight unexpected because in child class we cannot know, which private methods exists in a parent class and vice versa. So, remember that if you defined a private static method, you cannot place method with the same name in child class. slorenzo
<?php class parentClass { public function someMethod() { } } class childClass extends parentClass { public final function someMethod() { } //override parent function } $class = new childClass; $class->someMethod(); //call the override function in chield class ?> |
Change LanguageIntroduction The Basics Autoloading Objects Constructors and Destructors Visibility Scope Resolution Operator (::) Static Keyword Class Constants Class Abstraction Object Interfaces Overloading Object Iteration Patterns Magic Methods Final Keyword Object cloning Comparing objects Reflection Type Hinting Late Static Bindings |