pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/php-fig/per-coding-style/commit/64d3c264953a25fd0d3c38c7b364c8ac148fe5de

/> Updated as per PR discussions · php-fig/per-coding-style@64d3c26 · GitHub
Skip to content

Commit 64d3c26

Browse files
committed
Updated as per PR discussions
1 parent 49970b4 commit 64d3c26

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

spec.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,13 +1088,18 @@ if (
10881088

10891089
### 5.2 `switch`, `case`, `match`
10901090

1091-
A `switch` structure looks like the following. Note the placement of
1092-
parentheses, spaces, and braces. The `case` statement MUST be indented once
1093-
from `switch`, and the `break` keyword (or other terminating keywords) MUST be
1094-
indented at the same level as the `case` body. There MUST be a comment such as
1095-
`// no break` when fall-through is intentional in a non-empty `case` body.
1096-
The `case` and `default` keywords MUST use colons as shown in the sample code below.
1091+
A switch structure must follow the rules below:
10971092

1093+
* `case` statements MUST be indented one level from the `switch`.
1094+
* The `case` statements line MUST consist only of the `case` keyword, a single space, the case condition (an expression), and a colon.
1095+
* If the case condition is sufficiently complex to warrant being multi-line, it MUST be wrapped in parentheses, MUST have the opening parenthesis on the same line as the `case` keyword, and MUST end with a line containing only the closing parenthesis and colon, with no space between them.
1096+
* The body of a `case` statement MUST be indented one level from the `case`.
1097+
* If a non-empty case intends to continue into the following case, then a clear comment MUST be included to highlight the deliberate lack of a `break`, `return`, or similar termination statement. Examples include "No break," "Deliberate fall-through," etc.
1098+
* All other non-empty cases MUST have a terminating `break`, `return`, or similar termination statement, even if they are the final one in the `switch` block.
1099+
* The `case` body MUST NOT be wrapped in `{}`.
1100+
* The default statement MUST be indented one level from the `switch`, and the default keyword MUST be followed by a colon.
1101+
1102+
See the example below.
10981103

10991104
```php
11001105
<?php
@@ -1105,7 +1110,7 @@ switch ($expr) {
11051110
break;
11061111
case 1:
11071112
echo 'Second case, which falls through';
1108-
// no break
1113+
// No break
11091114
case 2:
11101115
case 3:
11111116
case 4:
@@ -1134,6 +1139,18 @@ switch (
11341139
}
11351140
```
11361141

1142+
```php
1143+
<?php
1144+
1145+
switch (true) {
1146+
case (
1147+
$a === 10
1148+
&& $b === 20
1149+
):
1150+
break;
1151+
}
1152+
```
1153+
11371154
Similarly, a `match` expression looks like the following. Note the placement
11381155
of parentheses, spaces, and braces.
11391156

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy