note 96603 added to oop4.constructor
| From: | Anonymous at osu1 dot php dot net | Date: | Sun, 07 Mar 2010 19:26:53 +0000 |
| Subject: | note 96603 added to oop4.constructor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166762@lists.php.net to get a copy of this message | ||
re: "It is your responsibility to propagate the call to constructors upstream where
appropriate. "
eg, when you have
<?php
class A {
public function __construct() {
echo "constructing A";
}
}
$foo = new A(); // "constructing A"
class B extends A {
public function __construct() {
echo "constructing B";
}
}
$foo = new B(); // "constructing B"
?>
but you want:
<?php
$foo = new B(); // "constructing Aconstructing B"
?>
then you need to say:
<?php
class B extends A {
public function __construct() {
parent::__construct();
echo "constructing B";
}
}
?>
see the page on "parent" (http://www.php.net/manual/en/keyword.parent.php) for more info
----
Server IP: 69.147.83.197
Probable Submitter: 217.42.211.90
----
Manual Page -- http://www.php.net/manual/en/oop4.constructor.php
Edit -- https://master.php.net/note/edit/96603
Del: integrated -- https://master.php.net/note/delete/96603/integrated
Del: useless -- https://master.php.net/note/delete/96603/useless
Del: bad code -- https://master.php.net/note/delete/96603/bad+code
Del: spam -- https://master.php.net/note/delete/96603/spam
Del: non-english -- https://master.php.net/note/delete/96603/non-english
Del: in docs -- https://master.php.net/note/delete/96603/in+docs
Del: other reasons-- https://master.php.net/note/delete/96603
Reject -- https://master.php.net/note/reject/96603
Search -- https://master.php.net/manage/user-notes.php