php 子类 不写默认构造函数, 默认会调用父类构造函数

* Base.php

<?php

class Base {
    public function __construct() {
        echo __METHOD__.PHP_EOL;
    }
}

* Derived.php

<?php

class Derived extends Base {
    
    // public function __construct() {
    //     parent::__construct();
    //     echo __METHOD__.PHP_EOL;
    // }
    
}

* index.php

<?php

function __autoload($className) {
    include $className.'.php';
}

$d = new Derived();

php index.php

Base::__construct
 

猜你喜欢

转载自blog.csdn.net/fareast_mzh/article/details/85061659