-
Notifications
You must be signed in to change notification settings - Fork 0
/
poly.php
45 lines (41 loc) · 777 Bytes
/
poly.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
require_once 'common.php';
abstract class Animal{
abstract function sound();
}
class Cat extends Animal{
function sound(){
return "Mew";
}
}
class Dog extends Animal{
function sound(){
return "Gaf";
}
}
class Pinguin extends Animal{
function sound(){
return "piu";
}
}
class Ondater extends Animal{
function sound(){
return "hrum";
}
}
class Fish extends Animal{
function sound(){
return "";
}
}
//***********************
function animalChorus(Animal $animal){
p(get_class($animal) . " say: " . $animal->sound());
}
//*******************
$animals = [
new Cat(),new Dog(),new Fish(),new Ondater(),new Pinguin()
];
foreach ($animals as $animal) {
animalChorus($animal);
}