Why am I getting Fatal error when calling a parent's constructor?

后端 未结 5 2318
执念已碎
执念已碎 2021-02-11 17:07

I am extending one of the SPL (Standard PHP Library) classes and I am unable to call the parent\'s constructor. Here is the error I am getting:

Fatal erro

5条回答
  •  天命终不由人
    2021-02-11 18:00

    I got the same error. I have solved it by defining an empty constructor in the parent class. That way other classes don't have to define it. I think it's cleaner approach.

    If you still need to call the constructor you can do this.

    if (is_callable('parent::__construct')) {
        parent::__construct();
    }
    

提交回复
热议问题