note 106141 added to language.oop5.final
| From: | darkmantis at cybershade dot org | Date: | Thu, 13 Oct 2011 16:27:05 +0000 |
| Subject: | note 106141 added to language.oop5.final | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183853@lists.php.net to get a copy of this message | ||
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
----
Server IP: 92.48.74.199
Probable Submitter: 93.97.240.97
----
Manual Page -- http://www.php.net/manual/en/language.oop5.final.php
Edit -- https://master.php.net/note/edit/106141
Del: integrated -- https://master.php.net/note/delete/106141/integrated
Del: useless -- https://master.php.net/note/delete/106141/useless
Del: bad code -- https://master.php.net/note/delete/106141/bad+code
Del: spam -- https://master.php.net/note/delete/106141/spam
Del: non-english -- https://master.php.net/note/delete/106141/non-english
Del: in docs -- https://master.php.net/note/delete/106141/in+docs
Del: other reasons-- https://master.php.net/note/delete/106141
Reject -- https://master.php.net/note/reject/106141
Search -- https://master.php.net/manage/user-notes.php