Hierarchical inheritance means one parent class is used by many child classes.

<?php
class Animal {       
    public function eat() {
        echo "This animal eats food.<br>";
    }
}
class Dog extends Animal {   
    public function bark() {
        echo "Dog barks.<br>";
    }
}
class Cat extends Animal {  
    public function meow() {
        echo "Cat meows.<br>";
    }
}
$dog = new Dog();
$dog->eat();   
$dog->bark();
$cat = new Cat();
$cat->eat();   
$cat->meow();
?>
  • Animal - Parent class
  • Dog and Cat - Child classes
  • Both Dog and Cat can use the eat() method from Animal.