本文整理匯總了PHP中Dog::Greet方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dog::Greet方法的具體用法?PHP Dog::Greet怎麽用?PHP Dog::Greet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Dog
的用法示例。
在下文中一共展示了Dog::Greet方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: Describe
<?php
abstract class Animal
{
public $name;
public $age;
public function Describe()
{
return $this->name . ", " . $this->age . " years old";
}
public abstract function Greet();
}
class Dog extends Animal
{
public function Greet()
{
return "Woof!";
}
public function Describe()
{
return parent::Describe() . ", and I'm a dog!";
}
}
$animal = new Dog();
$animal->name = "Bob";
$animal->age = 7;
echo $animal->Describe();
echo $animal->Greet();
示例2: Greet
<?php
class Animal
{
public $name;
public function Greet()
{
return "Hello, I'm some sort of animal and my name is " . $this->name;
}
}
class Dog extends Animal
{
}
//$animal = new Animal();
//echo $animal->Greet();
$dog = new Dog();
$dog->name = "Bob";
echo $dog->Greet();