6. Operators
All binary and ternary (but not unary) operators MUST be preceded and followed by at least one space. This includes all arithmetic, comparison, assignment, bitwise, logical (excluding ! which is unary), string concatenation, type operators, trait operators (insteadof and as), and the single pipe operator (e.g. ExceptionType1 | ExceptionType2 $e).
<?php
if ($a === $b) {
$foo = $bar ?? $a ?? $b;
} elseif ($a > $b) {
$variable = $foo ? 'foo' : 'bar';
}
<?php
$short = 'foo';
$somethingLonger = 'bar';
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/6ea3c2e7-2f2b-4c86-9535-8b10319b40e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Multiple spaces before (or, less often, after) an operator can be useful when attempting to align operands.<?php
$short = 'foo';$somethingLonger = 'bar';
There are other cases, but that's one of the most common.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/c21a1db6-b7ac-4b8a-8a5c-0cd2b4e3eaed%40googlegroups.com.
I often find it helpful to align operators other than assignment operators, too. Comparison, bitwise, Boolean, arithmetic, and so on, are equally subject to operand alignment to improve readability. Which is why I said "operator" instead of "assignment operator", though my quick example only included the one type.
Yes, it was intentionally left open for alignment purpose.