Why aren't parent constructors being called?

六月ゝ 毕业季﹏ 提交于 2019-12-01 20:46:25

should not bookmark also create objects from each of its parent classes

That's entirely your choice to make, there is no requirement in the language to call the parent methods.

As the PHP manual concisely puts it:

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.

http://php.net/oop5.decon

While Java will call the no-arg constructor of the parent class if you don't call one specifically, PHP has no such feature. This allows you to do some work before calling the parent constructor, though you obviously shouldn't depend on any properties set by the parent constructor. ;)

BTW, as I stated in a comment, most of your calls that use self:: should be using $this-> instead. Only static methods are called using self::.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!