Inheritance in PHP is a concept of Object-Oriented Programming where a child class can use the properties and methods of a parent class.
Syntax:
Inheritance allows a child class to reuse the properties and methods of a parent class.
<?php
class ParentClass {
function method1(){
// parent code
}
}
class ChildClass extends ParentClass {
function method2(){
// child code
}
}
$obj = new ChildClass();
$obj->method1(); // from parent class
$obj->method2(); // from child class
?>Types of Inheritance:
- Simple Inheritance
- Multilevel Inheritance.
- Hierarchical Inheritance.
- Multiple Inheritance - PHP Not Support
| Inheritance Type | Support in PHP | Flow Chart | Code |
| Single Inheritance | YES | | |
| Multilevel Inheritance | YES | | |
| Hierarchical Inheritance | YES | | |
| Multiple Inheritance | NO |