<?php
class Animal {
protected $name;
public function __construct($name) {
$this->name = $name;
}
public function eat() {
echo "{$this->name} is eating.\n";
}
}
class Mammal extends Animal {
public function breathe() {
echo "{$this->name} is breathing.\n";
}
}
class Dog extends Mammal {
public function bark() {
echo "{$this->name} is barking.\n";
}
}
class Cat extends Mammal {
public function meow() {
echo "{$this->name} is meowing.\n";
}
}
// create objects of the classes
$dog = new Dog("Buddy");
$cat = new Cat("Smokey");
// call the methods
$dog->breathe(); // Buddy is breathing.
$dog->eat(); // Buddy is eating.
$dog->bark(); // Buddy is barking.
$cat->breathe(); // Smokey is breathing.
$cat->eat(); // Smokey is eating.
$cat->meow(); // Smokey is meowing.
?>