note 96603 deleted from oop4.constructor by danbrown
| From: | danbrown@php.net | Date: | Mon, 08 Mar 2010 16:35:46 +0000 |
| Subject: | note 96603 deleted from oop4.constructor by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166788@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
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