note 78137 added to language.oop.constructor
| From: | Brent at osu1 dot php dot net | Date: | Sat, 29 Sep 2007 17:35:02 +0000 |
| Subject: | note 78137 added to language.oop.constructor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130928@lists.php.net to get a copy of this message | ||
Another way to call the parent constructor without knowing the parent class, and without creating
another method such as constructor(), you can just do this:
class A
{
function A()
{
echo "Constructor for parent class called.<br>";
}
}
class B
{
function B()
{
// This calls the parent constructor ...
eval ("self::" . get_parent_class($this) . "();");
// Then you can put subclass constructor stuff ...
echo "Constructor for subclass called.";
}
}
----
Server IP: 69.147.83.197
Probable Submitter: 71.112.55.48
----
Manual Page -- http://www.php.net/manual/en/language.oop.constructor.php
Edit -- https://master.php.net/note/edit/78137
Del: integrated -- https://master.php.net/note/delete/78137/integrated
Del: useless -- https://master.php.net/note/delete/78137/useless
Del: bad code -- https://master.php.net/note/delete/78137/bad+code
Del: spam -- https://master.php.net/note/delete/78137/spam
Del: non-english -- https://master.php.net/note/delete/78137/non-english
Del: in docs -- https://master.php.net/note/delete/78137/in+docs
Del: other reasons-- https://master.php.net/note/delete/78137
Reject -- https://master.php.net/note/reject/78137
Search -- https://master.php.net/manage/user-notes.php