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

后端 未结 5 2255
执念已碎
执念已碎 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:06

    You may hack it like this:

    if (in_array('__construct', get_class_methods(get_parent_class($this)))) {
        parent::__construct();
    }
    

    but it's helpless.

    just declare constructor explicitly for every class. it's the right behavior.

提交回复
热议问题