Q
Q
Quber2015-07-09 03:56:40
PHP
Quber, 2015-07-09 03:56:40

Can a class inherit the parent's __toString() magic method?

There is a child class which is inherited from the parent. I want the __toString magic method from the parent to work in the child class. Is it possible?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2015-07-09
@Quber

maybe - ideone.com/TYhTAv honestly
, it was faster to check it yourself than to write a question here.

V
Vitaly Pukhov, 2015-07-09
@Neuroware

If you believe the OOP, then it is enough not to override the inherited function, in which case the one inherited from the parent will be executed. Although it depends on how the function is defined on the parent, for example it may not be inherited, in which case explicitly calling it will not work in the general case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question