开发者

PHP OOP Function Precedence

开发者 https://www.devze.com 2023-01-19 13:23 出处:网络
In OOP PHP, if I have a function defined in the parent class, and a modified version in the child class, and I call it from an i开发者_如何学运维nstantiated object of the child class, will it use the

In OOP PHP, if I have a function defined in the parent class, and a modified version in the child class, and I call it from an i开发者_如何学运维nstantiated object of the child class, will it use the child class's version of the function?

I am pretty sure it will, but I just wanted to double-check, as there's no way for me to check within a running application.


Yes, it absolutely will.

If you want to use the parent's version too, you must call parent::the_func() within the child's override of that function.

You must also call a parent's constructor if you override the constructor in the child. It is not called automatically.

0

精彩评论

暂无评论...
验证码 换一张
取 消