Exemple #1
0
     * @param $color
     */
    public function __construct($name, $age, $color)
    {
        $this->name = $name;
        $this->age = $age;
        $this->color = $color;
    }
    public function feed($food)
    {
        echo $this->name . " eats " . $food . " <br>";
        $this->sleepy = true;
    }
    public function sleep()
    {
        $this->sleepy = false;
    }
    public function isSleepy()
    {
        return $this->sleepy;
    }
}
$cat = new Cat("Barsik", 10, "#00ff00");
$smallCat = new Cat("Murzik", 1, "#0000ff");
$cat->feed("fish");
if ($cat->isSleepy()) {
    $cat->sleep();
}
$smallCat->feed("milk");
echo "Cat name: " . $cat->name . "<br>";
echo "Small cat name: " . $smallCat->name . "<br>";