git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@329168 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Sherif Ramadan 2013-01-16 19:18:10 +00:00
parent aa12b2b0eb
commit 73e27eb2d9

View file

@ -21,7 +21,9 @@
Parent constructors are not called implicitly if the child class defines
a constructor. In order to run a parent constructor, a call to
<function>parent::__construct</function> within the child constructor is
required.
required. If the child does not define a constructor then it may be inherited
from the parent class just like a normal class method (if it was not declared
as private).
</simpara>
</note>
<example>
@ -42,15 +44,27 @@ class SubClass extends BaseClass {
}
}
class OtherSubClass extends BaseClass {
// inherits BaseClass's constructor
}
// In BaseClass constructor
$obj = new BaseClass();
// In BaseClass constructor
// In SubClass constructor
$obj = new SubClass();
// In BaseClass constructor
$obj = new OtherSubClass();
?>
]]>
</programlisting>
</example>
<para>
For backwards compatibility, if PHP 5 cannot find a
<link linkend="object.construct">__construct()</link> function for a given class, it will
<link linkend="object.construct">__construct()</link> function for a given class, and the
class did not inherit one from a parent class, it will
search for the old-style constructor function, by the name of the class.
Effectively, it means that the only case that would have compatibility
issues is if the class had a method named
@ -122,7 +136,8 @@ $obj = new MyDestructableClass();
Like constructors, parent destructors will not be called implicitly by
the engine. In order to run a parent destructor, one would have to
explicitly call <function>parent::__destruct</function> in the destructor
body.
body. Also like constructors, a child class may inherit the parent's
destructor if it does not implement one itself.
</para>
<para>
The destructor will be called even if script execution is stopped using