Are abstract class constructors not implicitly called when a derived class is instantiated?

前端 未结 3 1368
轻奢々
轻奢々 2021-01-30 19:38

Take this example:

abstract class Base {
    function __construct() {
        echo \'Base __construct
\'; } } class Child extends Base { funct
3条回答
  •  逝去的感伤
    2021-01-30 20:30

    Well, I just found this in the docs:

    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.

提交回复
热议问题