|
1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | 2 | <!-- $Revision$ --> |
3 | | -<!-- EN-Revision: 83e2056f071742c44d2b0bdbc8574d73697c7a08 Maintainer: mumumu Status: ready --> |
| 3 | +<!-- EN-Revision: 2e5f2910f3a2a95dcbdaf580ba57a0b60b072c2a Maintainer: mumumu Status: ready --> |
4 | 4 | <chapter xml:id="language.enumerations" xmlns="http://docbook.org/ns/docbook"> |
5 | 5 | <title>列挙型(Enum)</title> |
6 | 6 | <sect1 xml:id="language.enumerations.overview"> |
@@ -230,10 +230,12 @@ enum Suit: string |
230 | 230 | </para> |
231 | 231 |
|
232 | 232 | <para> |
233 | | - スカラー値は、リテラルか、リテラルを表す式でなければいけません。 |
234 | | - 定数や定数式はサポートしていません。 |
| 233 | + スカラー値は、定数のスカラー式でなければいけません。 |
| 234 | + PHP 8.2.0 より前のバージョンでは、 |
| 235 | + スカラー値はリテラルか、リテラルを表す式でなければいけませんでした。 |
| 236 | + これは、定数や定数式はサポートされていなかったことを意味します。 |
235 | 237 | つまり、<literal>1 + 1</literal> は許されますが、 |
236 | | - <literal>1 + SOME_CONST</literal> は許されません。 |
| 238 | + <literal>1 + SOME_CONST</literal> は許されていませんでした。 |
237 | 239 | </para> |
238 | 240 |
|
239 | 241 | <para> |
@@ -525,12 +527,12 @@ enum Size |
525 | 527 | case Medium; |
526 | 528 | case Large; |
527 | 529 |
|
528 | | - public static function fromLength(int $cm): static |
| 530 | + public static function fromLength(int $cm): self |
529 | 531 | { |
530 | 532 | return match(true) { |
531 | | - $cm < 50 => static::Small, |
532 | | - $cm < 100 => static::Medium, |
533 | | - default => static::Large, |
| 533 | + $cm < 50 => self::Small, |
| 534 | + $cm < 100 => self::Medium, |
| 535 | + default => self::Large, |
534 | 536 | }; |
535 | 537 | } |
536 | 538 | } |
@@ -586,7 +588,7 @@ enum Size |
586 | 588 | 注意すべきことは、列挙型で <literal>use</literal> |
587 | 589 | されるトレイトには、プロパティが含まれていてはいけないという点です。 |
588 | 590 | <literal>use</literal> されるトレイトには、 |
589 | | - メソッドと static メソッドだけを含めることができます。 |
| 591 | + メソッドと static メソッドと、定数だけを含めることができます。 |
590 | 592 | プロパティを持つトレイトの場合、致命的なエラーが発生します。 |
591 | 593 | </para> |
592 | 594 |
|
@@ -934,7 +936,7 @@ function quux(ErrorCode $errorCode) |
934 | 936 | // 以下のようなコードを書くと、全ての case をカバーします |
935 | 937 | match ($errorCode) { |
936 | 938 | ErrorCode::SOMETHING_BROKE => true, |
937 | | - } |
| 939 | + }; |
938 | 940 | } |
939 | 941 |
|
940 | 942 | ?> |
@@ -1042,10 +1044,10 @@ enum UserStatus: string |
1042 | 1044 | public function label(): string |
1043 | 1045 | { |
1044 | 1046 | return match($this) { |
1045 | | - static::Pending => 'Pending', |
1046 | | - static::Active => 'Active', |
1047 | | - static::Suspended => 'Suspended', |
1048 | | - static::CanceledByUser => 'Canceled by user', |
| 1047 | + self::Pending => 'Pending', |
| 1048 | + self::Active => 'Active', |
| 1049 | + self::Suspended => 'Suspended', |
| 1050 | + self::CanceledByUser => 'Canceled by user', |
1049 | 1051 | }; |
1050 | 1052 | } |
1051 | 1053 | } |
|
0 commit comments