本文整理匯總了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);
}
示例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();
示例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);
示例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;