Skip to content

Commit 145af4e

Browse files
Create "Operators placement" section
1 parent 1e76f5e commit 145af4e

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

spec.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,10 +1057,6 @@ and `:` characters:
10571057

10581058
```php
10591059
$variable = $foo ? 'foo' : 'bar';
1060-
1061-
$variableMultiLine = $foo
1062-
? 'foo'
1063-
: 'bar';
10641060
```
10651061

10661062
When the middle operand of the conditional operator is omitted, the operator
@@ -1070,6 +1066,25 @@ MUST follow the same style rules as other binary [comparison][] operators:
10701066
$variable = $foo ?: 'bar';
10711067
```
10721068

1069+
### 6.4. Operator's placement
1070+
1071+
When a statement that includes an operator must be split into multiple lines,
1072+
the operator SHOULD be placed at the beginning of the new line.
1073+
1074+
```php
1075+
<?php
1076+
1077+
$variable1 = $possibleNullableExpr
1078+
?? 'fallback';
1079+
1080+
$variable2 = $ternaryOperatorExpr
1081+
? 'fizz'
1082+
: 'buzz';
1083+
1084+
$variable3 = $elvisExpr
1085+
?: 'qix';
1086+
```
1087+
10731088
## 7. Closures
10741089

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

0 commit comments

Comments
 (0)