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:

  1.  Simple Inheritance
  2.  Multilevel Inheritance.
  3.  Hierarchical Inheritance.

 

S.No.Inheritance TypeSupport in PHPFlow ChartCode
1Single InheritanceYES
class Animal {
                        // Properties and methods
                    }
                    class Dog extends Animal {
                        // Properties and methods specific to Dog
                    }
                    
2Multilevel 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 
} 
 
3Hierarchical 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
                    }
                    
4Multiple InheritanceNO