note 118054 added to language.oop5.abstract
| From: | rmoisto at gmail dot com | Date: | Sat, 26 Sep 2015 15:26:48 +0000 |
| Subject: | note 118054 added to language.oop5.abstract | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203854@lists.php.net to get a copy of this message | ||
The self keyword in an abstract class will refer to the abstract class itself, not the extending
class no matter what.
For instance the following code looks really pretty, yet results in a Fatal error (Cannot
instantiate abstract class Basic).
<?php
abstract class Basic {
public static function doWork() {
return (new self())->work();
}
abstract protected function work();
}
class Keeks extends Basic {
protected function work() {
return 'Keeks';
}
}
echo Keeks::doWork();
?>
----
Server IP: 72.52.91.14
Probable Submitter: 2001:7d0:88d9:2d01:a1d9:1e99:45e7:adb8
----
Manual Page -- http://php.net/manual/en/language.oop5.abstract.php
Edit -- https://master.php.net/note/edit/118054
Del: integrated -- https://master.php.net/note/delete/118054/integrated
Del: useless -- https://master.php.net/note/delete/118054/useless
Del: bad code -- https://master.php.net/note/delete/118054/bad+code
Del: spam -- https://master.php.net/note/delete/118054/spam
Del: non-english -- https://master.php.net/note/delete/118054/non-english
Del: in docs -- https://master.php.net/note/delete/118054/in+docs
Del: other reasons-- https://master.php.net/note/delete/118054
Reject -- https://master.php.net/note/reject/118054
Search -- https://master.php.net/manage/user-notes.php