File tree Expand file tree Collapse file tree 2 files changed +92
-0
lines changed Expand file tree Collapse file tree 2 files changed +92
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Backed Enum with multiple implementing interfaces
3
+ --FILE--
4
+ <?php
5
+
6
+ interface Colorful {
7
+ public function color (): string ;
8
+ }
9
+
10
+ interface Shaped {
11
+ public function shape (): string ;
12
+ }
13
+
14
+ interface ExtendedShaped extends Shaped {
15
+ }
16
+
17
+ enum Suit: string implements Colorful, ExtendedShaped {
18
+ case Hearts = 'H ' ;
19
+ case Diamonds = 'D ' ;
20
+ case Clubs = 'C ' ;
21
+ case Spades = 'S ' ;
22
+
23
+ public function color (): string {
24
+ return match ($ this ) {
25
+ self ::Hearts, self ::Diamonds => 'Red ' ,
26
+ self ::Clubs, self ::Spades => 'Black ' ,
27
+ };
28
+ }
29
+
30
+ public function shape (): string {
31
+ return match ($ this ) {
32
+ self ::Hearts => 'heart ' ,
33
+ self ::Diamonds => 'diamond ' ,
34
+ self ::Clubs => 'club ' ,
35
+ self ::Spades => 'spade ' ,
36
+ };
37
+ }
38
+ }
39
+
40
+ echo Suit::Hearts->color () . "\n" ;
41
+ echo Suit::Hearts->shape () . "\n" ;
42
+ echo Suit::Diamonds->color () . "\n" ;
43
+ echo Suit::Diamonds->shape () . "\n" ;
44
+ echo Suit::Clubs->color () . "\n" ;
45
+ echo Suit::Clubs->shape () . "\n" ;
46
+ echo Suit::Spades->color () . "\n" ;
47
+ echo Suit::Spades->shape () . "\n" ;
48
+
49
+ ?>
50
+ --EXPECT--
51
+ Red
52
+ heart
53
+ Red
54
+ diamond
55
+ Black
56
+ club
57
+ Black
58
+ spade
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Backed Enum implements
3
+ --FILE--
4
+ <?php
5
+
6
+ interface Colorful {
7
+ public function color (): string ;
8
+ }
9
+
10
+ enum Suit: string implements Colorful {
11
+ case Hearts = 'H ' ;
12
+ case Diamonds = 'D ' ;
13
+ case Clubs = 'C ' ;
14
+ case Spades = 'S ' ;
15
+
16
+ public function color (): string {
17
+ return match ($ this ) {
18
+ self ::Hearts, self ::Diamonds => 'Red ' ,
19
+ self ::Clubs, self ::Spades => 'Black ' ,
20
+ };
21
+ }
22
+ }
23
+
24
+ echo Suit::Hearts->color () . "\n" ;
25
+ echo Suit::Diamonds->color () . "\n" ;
26
+ echo Suit::Clubs->color () . "\n" ;
27
+ echo Suit::Spades->color () . "\n" ;
28
+
29
+ ?>
30
+ --EXPECT--
31
+ Red
32
+ Red
33
+ Black
34
+ Black
You can’t perform that action at this time.
0 commit comments