<?php
// define a parent class
class Animal {
public $name;
public $color;
function __construct($name, $color) {
$this->name = $name;
$this->color = $color;
}
function eat() {
echo "The " . $this->color . " " . $this->name . " is eating.<br>";
}
function sleep() {
echo "The " . $this->color . " " . $this->name . " is sleeping.<br>";
}
}
// define a child class that inherits from the parent class
class Dog extends Animal {
function bark() {
echo "The " . $this->color . " " . $this->name . " is barking.<br>";
}
}
// create an instance of the parent class
$animal = new Animal("animal", "gray");
$animal->eat();
$animal->sleep();
// create an instance of the child class
$dog = new Dog("dog", "brown");
$dog->eat();
$dog->sleep();
$dog->bark();
?>