<?php

$pets = array( new Dog("ぽち"), new Cat("たま", 1) );

foreach( $pets as $pet ) {
    $pet->play();
}

class Animal {
    var $name;

    function __construct($name) {
        $this->name = $name;
    }

    function play() {
    }
}

class Dog extends Animal {
    function __construct($name) {
        parent::__construct($name);
    }

    function play() {
        echo "わんわん！" . $this->name . "だよ\n";
    }
}

class Cat extends Animal {
    var $sleep;
    
    function __construct($name, $sleep) {
        parent::__construct($name);
        $this->sleep = $sleep;
    }

    function play() {
        echo "にゃん！" . $this->name . "だよ\n";
        if($this->sleep == 1) {
            echo "...でも寝る\n";
        }
    }
}
?>
