<?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();
<?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();