I think it's a good thing that PHP makes you call parent's constructor manually, because it allows child's constructor such as following:
public function __construct() {
// set up variables that parent::__construct() requires
$var1 = get_stuff_from_db();
$var2 = get_stuff_from_webservice();
parent::__construct($var1, $var2);
// continue setting up $this var
$this->default = 'Default';
$this->do_some_secret_stuff();
}
Or even:
public function __construct($param) {
// call differently based on condition
if (is_array($param))
$param['id'] = 0;
parent::__construct($param);
}
else {
parent::__construct($param, 0, TRUE);
}
// continue setting up $this var
$this->default = 'Default';
$this->do_some_secret_stuff();
}
Meaning, you are free to call the parent constructor anywhere within the child's and you are free to do stuff before and after the call. Ain't that a feature indeed?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…