本文整理汇总了PHP中Animal::fly方法的典型用法代码示例。如果您正苦于以下问题:PHP Animal::fly方法的具体用法?PHP Animal::fly怎么用?PHP Animal::fly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Animal
的用法示例。
在下文中一共展示了Animal::fly方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
class Dragon extends Animal
{
public function __construct($name)
{
$this->name = $name;
$this->hp = 170;
}
public function fly()
{
$this->hp -= 10;
}
public function display_hp()
{
parent::display_hp();
echo "This is a dragon!";
}
}
//-------END OF DRAGON CLASS CODE--------------//
$dragon1 = new Dragon('Eragon');
$dragon1->walk();
$dragon1->walk();
$dragon1->walk();
$dragon1->run();
$dragon1->run();
$dragon1->fly();
$dragon1->fly();
$dragon1->display_hp();
//--------TEST CODE--------------------//
$animal2 = new Animal('bob');
$animal2->fly();
//------END OF TEST-----------------//
示例2: __construct
{
$this->health += 5;
return $this;
}
}
class Dragon extends Animal
{
public function __construct($name)
{
$this->name = $name;
$this->health = 170;
}
public function fly()
{
$this->health -= 10;
return $this;
}
public function talk()
{
echo 'This is dragon!<br>';
return $this;
}
}
$lion = new Animal('lion');
$lion->walk()->walk()->walk()->run()->run()->displayHealth();
$dog = new Dog('dog');
$dog->walk()->walk()->walk()->run()->run()->pet()->displayHealth();
$dragon = new Dragon('dragon');
$dragon->walk()->walk()->walk()->run()->run()->fly()->fly()->talk()->displayHealth();
$lion->fly();