Inheritance in PHP
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
The process of deriving or making a new class from old class is known as inheritance .
syntax for decleration of child or new class :-
class childClassName extends ParentClassName
{
statement ;
}
- The code is being re-used from one class to another. We need not required to re-write the same thing again and again.
- Extensibility is one of the advantages of the inheritance in which we can extend the base class feature without making little or no changes to fulfill the business requirements.
- we don’t have to describe similar property or method in upcoming class we can extends all the property of parent class using inheritance.
Types of Inheritance
- Single Inheritance
- Multi-layer inheritance
- hierarchical inheritance
If single class is derived or made from one parent or old class is known as Single Inheritance
eg:-
In the multi-level inheritance, we will inherit the one base class into a derived class, and then the derived class will become the base class for another derived class.
In the hierarchical inheritance, we will inherit the one base class into multiple derived classes.