本文整理汇总了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);
}
示例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);
示例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);
示例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);