Skip to content
Open
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
40 changes: 28 additions & 12 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1292,18 +1292,29 @@ $intValue = (int) $input;

### 6.2. Binary operators

All binary [arithmetic][], [comparison][], [assignment][], [bitwise][],
[logical][], [string][], and [type][] operators MUST be preceded and
followed by at least one space:
All binary operators MUST be preceded and followed by at least one space:

```php
if ($a === $b) {
$foo = $bar ?? $a ?? $b;
} elseif ($a > $b) {
$foo = $a + $b * $c;
} else {
$foo = $a |> log(...) |> round(...);
}
```

As of writing, this applies to:

* `** * / % + -` [arithmetic][] operators
* `< <= > >= == != === !== <> <=>` [comparison][] operators
* `= += -= *= **= /= .= %= &= |= ^= <<= >>= ??=` [assignment][] operators
* `<< >> & ^ |` [bitwise][] operators
* `&& || and xor or` [logical][] operators
* `.` [string][] operator ("concatenation")
* `instanceof` [type][] operator
* `|>` [functional][] operator ("pipe")

### 6.3. Ternary operators

The conditional operator, also known simply as the ternary operator, MUST be
Expand Down Expand Up @@ -1341,6 +1352,10 @@ $variable2 = $possibleNullableExpr

$variable3 = $elvisExpr
?: 'qix';

$variable4 = '<foo>'
|> strtoupper(...)
|> htmlspecialchars(...);
```

## 7. Closures
Expand Down Expand Up @@ -1782,12 +1797,13 @@ class Demo

[PSR-1]: https://www.php-fig.org/psr/psr-1/
[PSR-12]: https://www.php-fig.org/psr/psr-12/
[keywords]: http://php.net/manual/en/reserved.keywords.php
[types]: http://php.net/manual/en/reserved.other-reserved-words.php
[arithmetic]: http://php.net/manual/en/language.operators.arithmetic.php
[assignment]: http://php.net/manual/en/language.operators.assignment.php
[comparison]: http://php.net/manual/en/language.operators.comparison.php
[bitwise]: http://php.net/manual/en/language.operators.bitwise.php
[logical]: http://php.net/manual/en/language.operators.logical.php
[string]: http://php.net/manual/en/language.operators.string.php
[type]: http://php.net/manual/en/language.operators.type.php
[keywords]: https://php.net/manual/en/reserved.keywords.php
[types]: https://php.net/manual/en/reserved.other-reserved-words.php
[arithmetic]: https://php.net/manual/en/language.operators.arithmetic.php
[assignment]: https://php.net/manual/en/language.operators.assignment.php
[comparison]: https://php.net/manual/en/language.operators.comparison.php
[bitwise]: https://php.net/manual/en/language.operators.bitwise.php
[logical]: https://php.net/manual/en/language.operators.logical.php
[string]: https://php.net/manual/en/language.operators.string.php
[type]: https://php.net/manual/en/language.operators.type.php
[functional]: https://php.net/manual/en/language.operators.functional.php