-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrait_type.php
More file actions
65 lines (51 loc) · 915 Bytes
/
Copy pathtrait_type.php
File metadata and controls
65 lines (51 loc) · 915 Bytes
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
interface Runnable{
public function run();
}
trait RunByLeg{
public function run(){
echo "足で走る\n";
}
}
trait RunByWheel{
public function run(){
echo "車輪で走る\n";
}
}
trait RunByHorse{
public function run(){
echo "馬で走る\n";
}
}
class Human implements Runnable {
use RunByLeg;
}
class Dog implements Runnable {
use RunByLeg;
}
class Car implements Runnable {
use RunByWheel;
}
class Knight implements Runnable{
use RunByHorse;
}
$human = new Human();
if ($human instanceof Runnable){
echo "人間は走れます\n";
$human->run();
}
$dog = new Dog();
if($dog instanceof Runnable){
echo "犬は走れます\n";
$dog->run();
}
$car = new Car();
if($car instanceof Runnable){
echo "車は走れます\n";
$car->run();
}
$knight = new Knight();
if($knight instanceof Runnable){
echo "騎士は走れます\n";
$knight->run();
}