Re: Construction
| From: | Paul Bissex | Date: | Sun, 27 Jun 2004 16:09:47 +0000 |
| Subject: | Re: Construction | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-189115@lists.php.net to get a copy of this message | ||
On Sat, 26 Jun 2004 20:51:58 -0700, Jason Davidson
<jason.davidson@gmail.com> wrote:
>
> If you instantiate a child class, the parent class constructor is not
> called, is there a reason for this? anyone know of plans to change
> this at all, ....
> the obvious workaround is to call the parents constructor inside the
> childs constructor, but this seems kinda strange.
I think it's unlikely to change. PHP5 also works this way, though it
uses constructor methods named "__construct" (in addition to allowing
old-style constructors with the name of the class).
<?php
// PHP5
class Foo
{
function __construct()
{
$this->x = "data";
}
}
class Bar extends Foo
{
function __construct()
{
parent::__construct();
$this->y = "more data";
}
}
?>
FWIW Python also requires child classes to call parent constructors
manually. Not sure what the justification is for this design decision
is, though, in either language. Anybody?
pb
--
paul bissex, e-scribe.com -- database-driven web development
413.585.8095
69.55.225.29
01061-0847
72°39'71"W 42°19'42"N