当前位置: 首页>>代码示例>>PHP>>正文


PHP Animal::run方法代码示例

本文整理汇总了PHP中Animal::run方法的典型用法代码示例。如果您正苦于以下问题:PHP Animal::run方法的具体用法?PHP Animal::run怎么用?PHP Animal::run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Animal的用法示例。


在下文中一共展示了Animal::run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: display_hp

    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()
    {
        $this->hp += 5;
    }
}
开发者ID:Ashkash28,项目名称:php_animal_oop,代码行数:31,代码来源:index.php

示例2: sleep

        } else {
            throw new ERR_NOT_FOUND("Sorry, the barn does not contain {$args['0']}.");
        }
        $resp->status()->add_message("{$args['0']} is now dead. Good job!");
        return Worker::WORKER_SUCCESS;
    }
    function do_work($id, $resp)
    {
        $animal = $this->get_animal($id);
        if ($animal['species'] == 'Araneus cavaticus') {
            $this->spin_web($animal['name'], $resp);
        } else {
            $resp->status()->add_message($animal['name'] . " is happily rolling around in the mud!");
        }
    }
    function spin_web($name, $resp)
    {
        $resp->status()->progress(10);
        $resp->status()->add_message("{$name} is beginning to spin a web.");
        sleep(30);
        $resp->status()->progress(50);
        $resp->status()->add_message("{$name} is still spinning...");
        sleep(30);
        $messages = array('SOME PIG', 'TERRIFIC', 'RADIANT', 'HUMBLE');
        $message = $messages[array_rand($messages)];
        $resp->status()->add_message("{$name}'s web is complete! It says: '{$message}'");
    }
}
$worker = new Animal($argv[1]);
$worker->run();
开发者ID:wqx081,项目名称:gearbox,代码行数:30,代码来源:workerBarn.php

示例3: make_them_sing

$animal_one->sound = "Ruff";
// The statements $animal_one->att_name call __get
// We call static attributes like this Class::$static_var
echo $animal_one->name . " says " . $animal_one->sound . " give me some " . $animal_one->favorite_food . " my id is " . $animal_one->id . " total animals = " . Animal::$number_of_animals . "<br /><br />";
// If we defined a constant in the class we would get its
// value like this Class::CONTANT
echo "Favorite Number " . Animal::PI . "<br />";
$animal_two = new Dog();
$animal_two->name = "Grover";
$animal_two->favorite_food = "Mushrooms";
$animal_two->sound = "Grrrrrrr";
// Even though we are referring to the Dog $number_of_animals it
// still increases even with subclasses
echo $animal_two->name . " says " . $animal_two->sound . " give me some " . $animal_two->favorite_food . " my id is " . $animal_two->id . " total animals = " . Dog::$number_of_animals . "<br /><br />";
// 2. Because of method overriding we get different results
$animal_one->run();
$animal_two->run();
// 3. final methods can't be overriden
$animal_one->what_is_good();
// 4. Example using __toString()
echo $animal_two;
// 5. You call a method defined in an interface like all others
$animal_two->sing();
// 6. You can also define functions that will except classes
// extending a secific class or interface
function make_them_sing(Singable $singing_animal)
{
    $singing_animal->sing();
}
// 6. Polymorphism states that different classes can have different
// behaviors for the same function. The compiler is smart enough to
开发者ID:BugsBunny33,项目名称:VezbePHP,代码行数:31,代码来源:vezba_OOP_youtube.php


注:本文中的Animal::run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。