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


PHP Dog::run方法代码示例

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


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

示例1: __construct

    public function __construct($name)
    {
        $this->name = $name;
        $this->hp = 150;
    }
    public function pet()
    {
        $this->hp += 5;
    }
}
//---------END OF DOG CLASS CODE-------------//
$dog1 = new Dog('bill');
$dog1->walk();
$dog1->walk();
$dog1->walk();
$dog1->run();
$dog1->run();
$dog1->pet();
$dog1->display_hp();
//-----DRAGON CLASS------------------------//
class Dragon extends Animal
{
    public function __construct($name)
    {
        $this->name = $name;
        $this->hp = 170;
    }
    public function fly()
    {
        $this->hp -= 10;
    }
开发者ID:Ashkash28,项目名称:php_animal_oop,代码行数:31,代码来源:index.php

示例2: __get

    }
    public function __get($key)
    {
        return $this->data[$key];
    }
    public function __call($name, $arguments)
    {
        var_dump($name);
        var_dump($arguments);
    }
    public static function __callStatic($name, $arguments)
    {
        var_dump($name);
        var_dump($arguments);
    }
    public function bark()
    {
        echo "Bark!";
    }
    public static function warning()
    {
        echo "Dog Bite!";
    }
}
Dog::run("Pyay", 300);
$dog = new Dog("Aung Net", "Red");
$dog->test = "Testing";
$dog->goo = "Foo";
echo $dog->test;
echo $dog->goo;
$dog->dance("Aung Net", 4);
开发者ID:phpcrazy,项目名称:wpa20,代码行数:31,代码来源:classintro.php

示例3: make_them_sing

// 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
// just figure out which function to execute
开发者ID:BugsBunny33,项目名称:VezbePHP,代码行数:31,代码来源:vezba_OOP_youtube.php


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