Aligning Blocks of Assignments

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.

Equals signs aligned

$shortVar <em>=</em> (1 + 2); $veryLongVarName <em>=</em> 'string'; $var <em>=</em> foo($bar, $baz, $quux);

Not aligned; harder to read

$shortVar <em>=</em> (1 + 2); $veryLongVarName <em>=</em> 'string'; $var <em>=</em> foo($bar, $baz, $quux);
When using plus-equals, minus-equals etc. still ensure the equals signs are aligned to one space after the longest variable name.

Equals signs aligned; only one space after longest var name

$shortVar <em>+= </em>1; $veryLongVarName<em> = </em>1;

Two spaces after longest var name

$shortVar <em> += </em>1; $veryLongVarName<em> = </em>1;

Equals signs aligned

$shortVar <em> = </em>1; $veryLongVarName<em> -= </em>1;

Equals signs not aligned

$shortVar <em> = </em>1; $veryLongVarName<em> -= </em>1;