The concept of inheritance in PHP is similar to other object-oriented programming languages, such as Java and C++. As in biological inheritance, a child inherits the properties of his parents; in PHP, a class can inherit properties from another class. It is a way to extend the functionality of a base class to the derived class.
Syntax:
For inheriting a class in PHP, we use the keyword “extends,” and the syntax for deriving a class is as follows:
class derived_class_name extends base_class_name {
// member functions of the derived class.
}
Different types of Inheritance:
- Simple Inheritance
- Multilevel Inheritance.
- Hierarchical Inheritance.
S.No. | Inheritance Type | Support in PHP | Flow Chart | Code |
1 | Single Inheritance | YES |
| |
2 | Multilevel Inheritance | YES |
| |
3 | Hierarchical Inheritance | YES |
| |
4 | Multiple Inheritance | NO |