note 51585 added to language.oop.constructor
| From: | phpnotes at ionws dot com | Date: | Tue, 05 Apr 2005 05:51:16 +0000 |
| Subject: | note 51585 added to language.oop.constructor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87473@lists.php.net to get a copy of this message | ||
Just to possibly clarify something on this page: if you create an object of a derived class and the
derived class has no constructor, then the base class's constructor will be automatically
called. For example:
<?php
class A {
function A() {
echo "A()\n";
}
}
class B extends A {
function foo() {
}
}
$bar = new B;
// output: A()
?>
But if the derived class has a constructor, the base constructor is not automatically called. For
example:
<?php
class A {
function A() {
echo "A()\n";
}
}
class B extends A {
function B() {
echo "B()\n";
}
function foo() {
}
}
$bar = new B;
// output: B()
?>
----
Manual Page -- http://www.php.net/manual/en/language.oop.constructor.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51585
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51585&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51585&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51585&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51585&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51585&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51585&report=yes
Search -- http://master.php.net/manage/user-notes.php