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 19-29. 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 19-30. 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)
?>


Links
Apollo Hosting $6.96/mo
  • 3GB Diskspace
  • 100GB Bandwidth
  • Live 24/7 Support
  • SpamAssassin
  • Urchin Web Analytics

HostMonster $5.95/mo
  • 200GB Diskspace
  • 2000GB Bandwidth
  • Host Unlimited Domains
  • SSH Access
  • SSL FTP Stats
  • CGI Ruby Perl PHP MySQL
  • Free Domain

iPowerWeb $7.95/mo
  • 50GB Diskspace
  • 750GB Bandwidth
  • CGI Perl PHP SSI SSL MySQL
  • Free Domain Name

Hosting Companies


Partners


Quick Search
Platform

Price

Diskspace

Bandwidth


 Advance Search
 Show All Companies


Reference & Manual

If you are looking for dedicated servers, look no further. HostPulse.com is a site devoted to help web users find cheap web hosting and dedicated servers.


Free Sitemap Generator Host Login/Register | Contact Us | Terms | Add Links
Thumbnails by Thumbshots.org © 2002-2008 CheapHostDir.com