backed-implements-multiple.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. Backed Enum with multiple implementing interfaces
  3. --FILE--
  4. <?php
  5. interface Colorful {
  6. public function color(): string;
  7. }
  8. interface Shaped {
  9. public function shape(): string;
  10. }
  11. interface ExtendedShaped extends Shaped {
  12. }
  13. enum Suit: string implements Colorful, ExtendedShaped {
  14. case Hearts = 'H';
  15. case Diamonds = 'D';
  16. case Clubs = 'C';
  17. case Spades = 'S';
  18. public function color(): string {
  19. return match ($this) {
  20. self::Hearts, self::Diamonds => 'Red',
  21. self::Clubs, self::Spades => 'Black',
  22. };
  23. }
  24. public function shape(): string {
  25. return match ($this) {
  26. self::Hearts => 'heart',
  27. self::Diamonds => 'diamond',
  28. self::Clubs => 'club',
  29. self::Spades => 'spade',
  30. };
  31. }
  32. }
  33. echo Suit::Hearts->color() . "\n";
  34. echo Suit::Hearts->shape() . "\n";
  35. echo Suit::Diamonds->color() . "\n";
  36. echo Suit::Diamonds->shape() . "\n";
  37. echo Suit::Clubs->color() . "\n";
  38. echo Suit::Clubs->shape() . "\n";
  39. echo Suit::Spades->color() . "\n";
  40. echo Suit::Spades->shape() . "\n";
  41. ?>
  42. --EXPECT--
  43. Red
  44. heart
  45. Red
  46. diamond
  47. Black
  48. club
  49. Black
  50. spade