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:

  1.  Simple Inheritance 
  2.  Multilevel Inheritance.
  3.  Hierarchical Inheritance.
  4. Multiple Inheritance -  PHP Not Support

 

Inheritance TypeSupport in PHPFlow ChartCode
Single InheritanceYES
class Animal {
// Properties and methods
}
class Dog extends Animal {
// Properties and methods specific to Dog
}                  
Multilevel InheritanceYES
class Animal { 
   // Properties and methods 
}
class Mammal extends Animal { 
   // Properties and methods specific to mammals 
}
class Dog extends Mammal { 
   // Properties and methods specific to dogs 
}  
Hierarchical InheritanceYES
class Animal {
// Properties and methods
}
class Dog extends Animal {
// Properties and methods specific to dogs
}
class Cat extends Animal {
// Properties and methods specific to cats
}
Multiple InheritanceNO