Skip to content

Add ternary operator on multi-line #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,28 @@ MUST follow the same style rules as other binary [comparison][] operators:
$variable = $foo ?: 'bar';
```

### 6.4. Operator's placement

A statement that includes an operator MAY be split across multiple lines, where
each subsequent line is indented once. When doing so, the operator MUST be
placed at the beginning of the new line; ternaries MUST occupy 3 lines, never 2.

For example:

```php
<?php

$variable1 = $ternaryOperatorExpr
? 'fizz'
: 'buzz';

$variable2 = $possibleNullableExpr
?? 'fallback';

$variable3 = $elvisExpr
?: 'qix';
```

## 7. Closures

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