Related Links : Search Engine Optimization | | Search Engine Marketing | Online Marketing | Freelance Programmer| SEO Thailand | SEO Expert | SEO services | PHP Programmer Thailand | SEO Tutorial | What is SEO |

  Home Our SEO Services SEO Expert Consultant Php Programmer Keyword Suggestion Scripts|Articles| Email : sachin {at} jainsachin {dot} com

PHP | Final Keyword | Manual | Tutorial | Help

SEO Services



Website Programming in PHP / MYSQL



SEO Tools




    Friends


      Final Keyword

      Final Keyword

      PHP 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 #1 Final methods example

      <?php
      class 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

      <?php
      final class BaseClass {
         public function 
      test() {
             echo 
      "BaseClass::test() called\n";
         }

         
      // Here it doesn't matter if you specify the function as final or not
         
      final public function moreTesting() {
             echo 
      "BaseClass::moreTesting() called\n";
         }
      }

      class 
      ChildClass extends BaseClass {
      }
      // Results in Fatal error: Class ChildClass may not inherit from final class (BaseClass)
      ?>

      SEO Tutorial / Articles





      Php / Mysql Tutorial



      Articles



        Other Topics



        SEO by Jainsachin