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


PHP Dog::setName方法代碼示例

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


在下文中一共展示了Dog::setName方法的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: dirname

<?php 
require_once dirname(__FILE__) . '/Dog.php';
$josefine = new Dog("Josefine", "Labrador", "Male");
$josefine->sayWoof(true);
$harriet = new Dog("Harriet", "Golden retriever", "Female");
$harriet->sayWoof(false);
$harriet->setName("Harry");
$harriet->sayWoof("Male");
$harriet->sayWoof(true);
開發者ID:kopche,項目名稱:PHP-MySQL-Course,代碼行數:9,代碼來源:index.php

示例3: getName

        $this->name = $name;
    }
}
class Dog extends Animal
{
    public function getName()
    {
        return $this->name;
    }
    public function setName($name)
    {
        $this->name = $name;
    }
}
class Squirrel extends Animal
{
}
class Vet
{
    public function treat(Animal $animal)
    {
        echo 'The vet has treated ' . $animal->getName();
    }
}
$cat = new Cat();
$cat->setName('Felix');
$dog = new Dog();
$dog->setName('Ella');
//$s = new Squirrel();
$vet = new Vet();
$vet->treat($cat);
開發者ID:anatai,項目名稱:manray,代碼行數:31,代碼來源:example2.php

示例4: 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


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