Liam Bailey
Liam Bailey

Reputation: 5905

PHP OOP Function Precedence

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 instantiated 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.

Upvotes: 0

Views: 199

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191749

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.

Upvotes: 5

Related Questions