16
Why can't I use code like this?
<?php
class NoConstructor {
}
class ChildWithConstructor extends NoConstructor {
public function __construct() {
parent::__construct();
// do something
}
}
$foo = new ChildWithConstructor();
// **Fatal error: Cannot call constructor in file.php on line 8**
Eg. Java classes have default, no args constructor. It can be called even if it's not explicitly defined.
PHP behavior can cause troubles when we remove no args constructor from parent class, eg. when we think it's not needed any more.
Does anyone know why PHP creators made it this way?