Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jun 2018
    Posts
    61

    Can you extend a Final defined class in php?

    Can you extend a Final defined class in php?

  2. #2
    Registered User
    Join Date
    Apr 2018
    Posts
    118
    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.

  3. #3
    Registered User
    Join Date
    Jun 2018
    Posts
    1,416
    class can declared final to indicate that it cannot be extended; that is, one cannot declare subclasses of a final class. A final class cannot be extended. Final method can not be override by the child class. Class variables cannot be declare as final.

  4. #4
    Registered User
    Join Date
    Feb 2018
    Posts
    145
    Can you extend a Final defined class in php?

  5. #5
    Registered User
    Join Date
    Apr 2014
    Location
    india
    Posts
    407
    A final class is a class that cannot be extended. To declare a class as final, you need to prefix the ‘class’ keyword with ‘final’. Example below.

    final class BaseClass {
    public function myMethod() {
    echo "BaseClass method called";
    }
    }

    //this will cause Compile error
    class DerivedClass extends BaseClass {
    public function myMethod() {
    echo "DerivedClass method called";
    }
    }

    $c = new DerivedClass();
    $c->myMethod();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

  Find Web Hosting      
  Shared Web Hosting UNIX & Linux Web Hosting Windows Web Hosting Adult Web Hosting
  ASP ASP.NET Web Hosting Reseller Web Hosting VPS Web Hosting Managed Web Hosting
  Cloud Web Hosting Dedicated Server E-commerce Web Hosting Cheap Web Hosting


Premium Partners:


Visit forums.thewebhostbiz.com: to discuss the web hosting business, buy and sell websites and domain names, and discuss current web hosting tools and software.