{ } protected abstract function live(); protected abstract function communicate($tool); } class Animals extends Living { protected function live() { echo 'Search food ... ' . PHP_EOL; } public function communicate($tool, $cantalk = false) { echo 'Animals can\'t use' . $tool . ' and they ' . ($cantalk ? 'can' : 'can\'t') . ' talk.' . PHP_EOL; } } class Human extends Living { protected function live() { echo 'Work and make money ...' . PHP_EOL; } public function communicate($tool, $cantalk = true) { echo 'Human beings can use ' . $tool . ' and they ' . ($cantalk ? 'can' : 'can\'t') . ' talk.' . PHP_EOL; } } $animal = new Animals(); $animal->communicate('phone', false); $human = new Human(); $human->communicate('phone', true);
<?php class Animals { public function move() { echo __METHOD__ . "<br/>"; } } class Mammals extends Animals { } $animal = new Animals(); $animal->move(); $mammal = new Mammals(); $mammal->move(); // you still can call the method from the parent class, because Mammals inherits it
public function __construct($name, $gender, $health, $species) { parent::__construct($name, $gender, $health); $this->species = $species; }
public function testHydrateWithNewData() { $object = new Animals(); $object->horse = 'goat'; $object->hydrate(); $this->assertEquals('goat', $object->horse); }
<?php function __autoload($className) { include 'classes/' . $className . '.php'; } $kermit = new Animals("Kermit", "male", 100); $dikkie = new Animals("Dikkie", "male", 90); $flipper = new Animals("Flipper", "female", 80); $simba = new Lion("Simba", "Male", 100, "Congo lion"); $scar = new Lion("Scar", "Male", 100, "Kenia lion"); $zeke = new Zebra("Zeke", "Male", 100, "Quagga"); $zana = new Zebra("Zana", "Male", 100, "Selous"); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <link href="css/style.css" rel="stylesheet" type="text/css"> </head> <body> <p><?php echo $kermit->getName(); ?> is van het geslacht <?php echo $kermit->getGender(); ?> en heeft momenteel <?php echo $kermit->getHealth();
public function __construct($name, $age, $date_arrived, $bird_type) { parent::__construct($name, $age, $date_arrived); $this->bird_type = $bird_type; }