Answer the question
In order to leave comments, you need to log in
How to add a method in a child class?
Sap, habr, there is a problem I
just recently started to study OOP in PHP and ran into a problem - inheritance is undoubtedly a huge advantage of OOP, but I still don’t have a problem with its use, but specifically with inheritance of methods
Suppose there is a chair class, and in it variables $price, discount, final_price have method:
printer () {
echo ("Price:{$this->price}"."Discount:{$this->discount}");
echo ("Final price: {$this->final_price}");
}
Let's assume that two echoes cannot be combined into one.
Well, there is a class that inherits the whole thing, it has the constant MATERIAL = “wood”, so here's how you can supplement the printer () method so that it also outputs constant MATERIAL with another echo?
This is for an example, and if it is short and clear, then how to extend the method of the parent class in the inherited one?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question