note 114005 added to language.oop5.late-static-bindings
| From: | mhh1422athotmaildotcom | Date: | Sun, 29 Dec 2013 11:58:17 +0000 |
| Subject: | note 114005 added to language.oop5.late-static-bindings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198047@lists.php.net to get a copy of this message | ||
For abstract classes with static factory method, you can use the static keyword instead of self like
the following:
<?php
abstract class A{
static function create(){
//return new self(); //Fatal error: Cannot instantiate abstract class A
return new static(); //this is the correct way
}
}
class B extends A{
}
$obj=B::create();
var_dump($obj);
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/language.oop5.late-static-bindings.php
Edit -- https://master.php.net/note/edit/114005
Del: integrated -- https://master.php.net/note/delete/114005/integrated
Del: useless -- https://master.php.net/note/delete/114005/useless
Del: bad code -- https://master.php.net/note/delete/114005/bad+code
Del: spam -- https://master.php.net/note/delete/114005/spam
Del: non-english -- https://master.php.net/note/delete/114005/non-english
Del: in docs -- https://master.php.net/note/delete/114005/in+docs
Del: other reasons-- https://master.php.net/note/delete/114005
Reject -- https://master.php.net/note/reject/114005
Search -- https://master.php.net/manage/user-notes.php