Exemple #1
0
<?php

include 'inc/class.pet.php';
include 'inc/class.canadianpet.php';
include 'inc/class.apple.php';
$sam = new Pet('Sam');
$apple = new Apple();
$sam->eatApple($apple);
echo $sam->getEnergy();
//echo Pet::getPetsCreatedTotal();
<?php

class Apple
{
    public $calories = 100;
}
class pet
{
    private $energy;
    public function eatApple(Apple $apple)
    {
        $this->energy += $apple->calories;
    }
    public function getEnergy()
    {
        return 'Current Energy: ' . $this->energy . '<br>';
    }
}
$jack = new Pet('Jack');
$apple = new Apple();
$jack->eatApple(new Apple());
echo $jack->getEnergy();