[doc-en] master: enumerations: Amend the CS of the code examples (#4088)

From: Date: Fri, 05 Jun 2026 12:50:14 +0000
Subject: [doc-en] master: enumerations: Amend the CS of the code examples (#4088)
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-23348@lists.php.net to get a copy of this message
Author: Mikhail Alferov (mmalferov) Committer: GitHub (web-flow) Pusher: jordikroon Date: 2026-06-05T14:50:12+02:00 Commit: https://github.com/php/doc-en/commit/4c158f4a34c8f869a43f9f0bd5a4897fb35cec89 Raw diff: https://github.com/php/doc-en/commit/4c158f4a34c8f869a43f9f0bd5a4897fb35cec89.diff enumerations: Amend the CS of the code examples (#4088) * enumerations.xml Amend the CS of the code examples Changed paths: M language/enumerations.xml Diff: diff --git a/language/enumerations.xml b/language/enumerations.xml index 997897015312..840fe9ef2dc8 100644 --- a/language/enumerations.xml +++ b/language/enumerations.xml @@ -37,6 +37,7 @@ <programlisting role="php" annotations="non-interactive"> <![CDATA[ <?php + enum Suit { case Hearts; @@ -59,6 +60,7 @@ enum Suit <programlisting role="php"> <![CDATA[ <?php + enum Suit { case Hearts; @@ -105,6 +107,7 @@ pick_a_card('Spades'); <programlisting role="php"> <![CDATA[ <?php + enum Suit { case Hearts; @@ -155,6 +158,7 @@ if ($a !== 'Spades') { <programlisting role="php"> <![CDATA[ <?php + enum Suit { case Hearts; @@ -193,6 +197,7 @@ print Suit::Spades->name; <programlisting role="php" annotations="non-interactive"> <![CDATA[ <?php + enum Suit: string { case Hearts = 'H'; @@ -235,6 +240,7 @@ enum Suit: string <programlisting role="php"> <![CDATA[ <?php + enum Suit: string { case Hearts = 'H'; @@ -258,6 +264,7 @@ print Suit::Clubs->value; <programlisting role="php"> <![CDATA[ <?php + enum Suit: string { case Hearts = 'H'; @@ -307,6 +314,7 @@ $ref = &$suit->value; <programlisting role="php"> <![CDATA[ <?php + enum Suit: string { case Hearts = 'H'; @@ -352,6 +360,7 @@ print $suit->value . "\n"; <programlisting role="php"> <![CDATA[ <?php + interface Colorful { public function color(): string; @@ -367,7 +376,7 @@ enum Suit implements Colorful // Fulfills the interface contract. public function color(): string { - return match($this) { + return match ($this) { Suit::Hearts, Suit::Diamonds => 'Red', Suit::Clubs, Suit::Spades => 'Black', }; @@ -405,6 +414,7 @@ print Suit::Diamonds->shape(); // prints "Rectangle" <programlisting role="php" annotations="non-interactive"> <![CDATA[ <?php + interface Colorful { public function color(): string; @@ -420,7 +430,7 @@ enum Suit: string implements Colorful // Fulfills the interface contract. public function color(): string { - return match($this) { + return match ($this) { Suit::Hearts, Suit::Diamonds => 'Red', Suit::Clubs, Suit::Spades => 'Black', }; @@ -453,6 +463,7 @@ enum Suit: string implements Colorful <programlisting role="php" annotations="non-interactive"> <![CDATA[ <?php + interface Colorful { public function color(): string; @@ -469,7 +480,7 @@ final class Suit implements UnitEnum, Colorful public function color(): string { - return match($this) { + return match ($this) { Suit::Hearts, Suit::Diamonds => 'Red', Suit::Clubs, Suit::Spades => 'Black', }; @@ -508,6 +519,7 @@ final class Suit implements UnitEnum, Colorful <programlisting role="php"> <![CDATA[ <?php + enum Size { case Small; @@ -516,7 +528,7 @@ enum Size public static function fromLength(int $cm): self { - return match(true) { + return match (true) { $cm < 50 => self::Small, $cm < 100 => self::Medium, default => self::Large, @@ -550,6 +562,7 @@ var_dump(Size::fromLength(50)); <programlisting role="php"> <![CDATA[ <?php + enum Size { case Small; @@ -578,6 +591,7 @@ var_dump(Size::Huge); <programlisting role="php"> <![CDATA[ <?php + interface Colorful { public function color(): string; @@ -585,7 +599,8 @@ interface Colorful trait Rectangle { - public function shape(): string { + public function shape(): string + { return "Rectangle"; } } @@ -601,7 +616,7 @@ enum Suit implements Colorful public function color(): string { - return match($this) { + return match ($this) { Suit::Hearts, Suit::Diamonds => 'Red', Suit::Clubs, Suit::Spades => 'Black', }; @@ -636,6 +651,7 @@ var_dump($suit->shape()); <programlisting role="php" annotations="non-interactive"> <![CDATA[ <?php + // This is an entirely legal Enum definition. enum Direction implements ArrayAccess { @@ -734,6 +750,7 @@ $foo = new Foo(); <programlisting role="php" annotations="non-interactive"> <![CDATA[ <?php + $clovers = new Suit(); // Error: Cannot instantiate enum Suit @@ -757,6 +774,7 @@ $horseshoes = (new ReflectionClass(Suit::class))->newInstanceWithoutConstructor( <programlisting role="php"> <![CDATA[ <?php + enum Suit { case Hearts; @@ -796,6 +814,7 @@ var_dump(SuitBacked::cases()); <programlisting role="php"> <![CDATA[ <?php + enum Suit: string { case Hearts = 'H'; @@ -831,11 +850,14 @@ print serialize(Suit::Hearts); <programlisting role="php"> <![CDATA[ <?php -enum Foo { + +enum Foo +{ case Bar; } -enum Baz: int { +enum Baz: int +{ case Beep = 5; } @@ -868,12 +890,14 @@ Baz Enum:int { <programlisting role="php" annotations="non-interactive"> <![CDATA[ <?php + class A {} class B extends A {} function foo(A $a) {} -function bar(B $b) { +function bar(B $b) +{ foo($b); } ]]> @@ -892,7 +916,9 @@ function bar(B $b) { <programlisting role="php" annotations="non-interactive"> <![CDATA[ <?php -enum ErrorCode { + +enum ErrorCode +{ case SOMETHING_BROKE; } @@ -919,13 +945,16 @@ function quux(ErrorCode $errorCode) <programlisting role="php" annotations="non-interactive"> <![CDATA[ <?php + // Thought experiment code where enums are not final. // Note, this won't actually work in PHP. -enum MoreErrorCode extends ErrorCode { +enum MoreErrorCode extends ErrorCode +{ case PEBKAC; } -function fot(MoreErrorCode $errorCode) { +function fot(MoreErrorCode $errorCode) +{ quux($errorCode); } @@ -957,6 +986,7 @@ fot(MoreErrorCode::PEBKAC); <programlisting role="php" annotations="non-interactive"> <![CDATA[ <?php + enum SortOrder { case Asc; @@ -986,6 +1016,7 @@ function query($fields, $filter, SortOrder $order = SortOrder::Asc) <programlisting role="php"> <![CDATA[ <?php + enum UserStatus: string { case Pending = 'P'; @@ -995,7 +1026,7 @@ enum UserStatus: string public function label(): string { - return match($this) { + return match ($this) { self::Pending => 'Pending', self::Active => 'Active', self::Suspended => 'Suspended', @@ -1025,6 +1056,7 @@ var_dump($status->label()); <programlisting role="php"> <![CDATA[ <?php + enum UserStatus: string { case Pending = 'P';

« previous php.doc.cvs (#23348) next »