1
<documentation title="Aligning Blocks of Assignments">
4
There should be one space on either side of an equals sign used to assign a value to a variable. In the case of a block of related assignments, more space may be inserted to promote readability.
8
<code title="Equals signs aligned">
10
$shortVar <em>=</em> (1 + 2);
11
$veryLongVarName <em>=</em> 'string';
12
$var <em>=</em> foo($bar, $baz, $quux);
15
<code title="Not aligned; harder to read">
17
$shortVar <em>=</em> (1 + 2);
18
$veryLongVarName <em>=</em> 'string';
19
$var <em>=</em> foo($bar, $baz, $quux);
25
When using plus-equals, minus-equals etc. still ensure the equals signs are aligned to one space after the longest variable name.
29
<code title="Equals signs aligned; only one space after longest var name">
31
$shortVar <em>+= </em>1;
32
$veryLongVarName<em> = </em>1;
35
<code title="Two spaces after longest var name">
37
$shortVar <em> += </em>1;
38
$veryLongVarName<em> = </em>1;
43
<code title="Equals signs aligned">
45
$shortVar <em> = </em>1;
46
$veryLongVarName<em> -= </em>1;
49
<code title="Equals signs not aligned">
51
$shortVar <em> = </em>1;
52
$veryLongVarName<em> -= </em>1;