在
PHP Constructors and Destructors documentation它说
Note: Parent constructors are not called implicitly if the child class
defines a constructor. In order to run a parent constructor,a call to
parent::__construct() within the child constructor is required.
但是,如果子类不调用构造函数,父构造函数是否仍然被调用?还是应该创建一个调用父构造函数的构造函数?
IE:
class BaseClass { function __construct() { print "In BaseClass constructor\n"; } } class SubClass extends BaseClass { function __construct() { parent::__construct(); } }