Ejemplo n.º 1
0
echo $animal->displayHealth();
echo "<br>";
class dog extends animal
{
    public function __construct($name)
    {
        $this->name = $name;
        $this->health = 150;
    }
    public function pet()
    {
        $this->health += 5;
    }
}
$dog = new dog("dog");
$dog->walk()->walk()->walk()->run()->run()->pet();
echo $dog->displayHealth();
echo "<br>";
class dragon extends animal
{
    public function __construct($name)
    {
        $this->health = 170;
        $this->name = $name;
        echo "<br>this is a dragon!";
    }
    public function fly()
    {
        $this->health -= 10;
        return $this;
    }
Ejemplo n.º 2
0
        echo "<br>";
        return $this;
    }
}
class dragon extends animal
{
    public function __construct($name)
    {
        parent::__construct($name);
        $this->health = 170;
    }
    public function fly()
    {
        echo "Flying..... ";
        echo "<br>";
        $this->health -= 10;
        return $this;
    }
    public function display_health()
    {
        echo "This is a dragon";
        echo "<br>";
        parent::display_health();
    }
}
$animal1 = new animal("Rhino");
$animal1->walk()->walk()->walk()->run()->run()->display_health();
$animal2 = new dog("Lance the dog walker");
$animal2->walk()->walk()->walk()->run()->run()->pet()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->run()->walk()->walk()->walk()->display_health();
$animal3 = new dragon("Elysian");
$animal3->walk()->walk()->walk()->run()->run()->fly()->fly()->display_health();