このようなコードを使用できないのはなぜですか?
<?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**
例えば。Java クラスにはデフォルトがあり、args コンストラクターはありません。明示的に定義されていなくても呼び出すことができます。
親クラスから args コンストラクターを削除しないと、PHP の動作が問題を引き起こす可能性があります。もう必要ないと思うとき。
PHP の作成者がなぜこのような方法をとったのか、誰か知っていますか?