コード例 #1
0
ファイル: pets3.php プロジェクト: ZoneMo/backup
 function play() {
 
     // Call the Pet::play() method:
     parent::play();
 
     echo "<p>$this->name is fetching.</p>";
 }
コード例 #2
0
ファイル: Dog.php プロジェクト: et4891/php-oop-ullman
 /**
  *echo "dog's name" is fetching
  */
 function play()
 {
     parent::play();
     //echo Satchel is playing
     echo "<p>{$this->name} is fetching. </p>";
     //echo Satchel is fetching.
 }
コード例 #3
0
 /**
  * Increase a pet's happiness level.
  *
  * Increases the pet's happiness level and destroys the item. 
  * 
  * @param Pet $pet 
  * @param integer $quantity
  * @return string The success message.
  **/
 public function playWith(Pet $pet, $quantity)
 {
     if ($quantity > $this->getQuantity()) {
         throw new ArgumentError("This stack does not have {$quantity} items.");
     }
     $pet->play($this->getHappinessBonus() * $quantity);
     $this->updateQuantity($this->getQuantity() - $quantity);
     return "{$pet->getPetName()} is happier now.";
 }
コード例 #4
0
ファイル: Cat.php プロジェクト: et4891/php-oop-ullman
 /**
  * echo "cat's name" is climbing
  */
 function play()
 {
     parent::play();
     echo "<p>{$this->name} is climbing</p>";
 }
コード例 #5
0
ファイル: pets2.php プロジェクト: raynaldmo/php-education
{
    function play()
    {
        echo "<p>{$this->name} is fetching.</p>";
    }
}
// End of Dog class.
# ***** END OF CLASSES ***** #
// Create a dog:
$dog = new Dog('Satchel');
// Create a cat:
$cat = new Cat('Bucky');
// Create an unknown type of pet:
$pet = new Pet('Rob');
// Feed them:
$dog->eat();
$cat->eat();
$pet->eat();
// Nap time:
$dog->sleep();
$cat->sleep();
$pet->sleep();
// Have them play:
$dog->play();
$cat->play();
$pet->play();
// Delete the objects:
unset($dog, $cat, $pet);
?>
</body>
</html>