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