note 106141 deleted from language.oop5.final by danbrown
| From: | danbrown@php.net | Date: | Thu, 13 Oct 2011 17:36:12 +0000 |
| Subject: | note 106141 deleted from language.oop5.final by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183862@lists.php.net to get a copy of this message | ||
Note Submitter: darkmantis at cybershade dot org
----
This may be irrelevant to you, but I just had an idea about âabstractâ classes and the
âfinalâ keyword. If you declare a class as abstract and the constructor of that class as
final, then the extending class will not work:
<?php
abstract class newClass{
final public function __construct(){
echo 'You failed xD';
}
}
class MyClass extends newClass{
public function __construct(){
echo 'Will this work?';
}
public static function myFunc(){
echo 'FooBar';
}
}
$init = new MyClass();
$init::myFunc();
?>
And that will return :
Fatal error: Cannot override final method newClass::__construct() in
C:\wamp\Projects\BMPortal\public_html\newPHPClass.php on line 16