Skip to content

Commit f8ced3a

Browse files
authored
Merge pull request #93 from JesusValera/patch-1
Add ternary operator on multi-line
2 parents 58a17b4 + f6998a2 commit f8ced3a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

spec.md

+22
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,28 @@ MUST follow the same style rules as other binary [comparison][] operators:
10661066
$variable = $foo ?: 'bar';
10671067
```
10681068

1069+
### 6.4. Operator's placement
1070+
1071+
A statement that includes an operator MAY be split across multiple lines, where
1072+
each subsequent line is indented once. When doing so, the operator MUST be
1073+
placed at the beginning of the new line; ternaries MUST occupy 3 lines, never 2.
1074+
1075+
For example:
1076+
1077+
```php
1078+
<?php
1079+
1080+
$variable1 = $ternaryOperatorExpr
1081+
? 'fizz'
1082+
: 'buzz';
1083+
1084+
$variable2 = $possibleNullableExpr
1085+
?? 'fallback';
1086+
1087+
$variable3 = $elvisExpr
1088+
?: 'qix';
1089+
```
1090+
10691091
## 7. Closures
10701092

10711093
Closures, also known as anonymous functions, MUST be declared with a space

0 commit comments

Comments
 (0)