當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Dog::getName方法代碼示例

本文整理匯總了PHP中Dog::getName方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dog::getName方法的具體用法?PHP Dog::getName怎麽用?PHP Dog::getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Dog的用法示例。


在下文中一共展示了Dog::getName方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testDog

 public function testDog()
 {
     $dog = new Dog("Benji");
     $this->assertEquals("Benji", $dog->getName());
     $this->assertEquals("Benji the Dog", (string) $dog);
     $dog->setName("Rover");
     $this->assertEquals("Rover", $dog->getName());
     $this->assertEquals("Rover the Dog", (string) $dog);
 }
開發者ID:SamyGhannad,項目名稱:CtCI-6th-Edition,代碼行數:9,代碼來源:AnimalTest.php

示例2: Animal

<?php

include "Dog.php";
include "Bird.php";
$animal = new Animal("jeffery the lion");
$animal->getName();
$doggy = new Dog("Timmy");
$doggy->getName();
$doggy->move();
$doggy->digHole();
$doggy->tryToFly();
$birdy = new Bird("Tweety");
$birdy->getName();
$birdy->move();
$birdy->tryToFly();
開發者ID:cloudEdwards,項目名稱:php-design-patterns,代碼行數:15,代碼來源:index.php

示例3: setName

 * Created by PhpStorm.
 * User: Jundat95
 * Date: 12/24/2015
 * Time: 9:24 AM
 */
abstract class Animal
{
    protected $name;
    public abstract function setName($name);
    public function getName()
    {
        return $this->name;
    }
}
class Dog extends Animal
{
    public $age = 5;
    public function getAge()
    {
        return $this->age;
    }
    // Override lai function Abstract cua class Animal
    public function setName($name)
    {
        $this->name = $name;
    }
}
$dog = new Dog();
$dog->setName('Dog Family');
echo $dog->getName();
var_dump($dog);
開發者ID:WHTGo,項目名稱:EXP-Training,代碼行數:31,代碼來源:inheritance.php

示例4: __construct

<?php

class Animal
{
    private $name;
    public function __construct($name)
    {
        $this->name = $name;
    }
    final function getName()
    {
        echo $this->name;
    }
}
class Dog extends Animal
{
    public function __construct($name)
    {
        echo 'Yo dawg!' . '<br />' . PHP_EOL;
        parent::__construct($name);
    }
}
$dog = new Dog('Sparky');
echo $dog->getName() . '<br />' . PHP_EOL;
開發者ID:Aeprox,項目名稱:ws1-sws-course-materials,代碼行數:24,代碼來源:05.php


注:本文中的Dog::getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。