Control Structure Spacing

Single line control structures must have no spaces after the condition opening parenthesis and before the condition closing parenthesis.

Valid: No space after the opening parenthesis in a single-line condition.

if <em>(</em>$expr) { }

Invalid: Space after the opening parenthesis in a single-line condition.

if <em>( </em>$expr) { }

Valid: No space before the closing parenthesis in a single-line condition.

if <em>(</em>$expr) { }

Invalid: Space before the closing parenthesis in a single-line condition.

if ($expr<em> )</em> { }
The condition of the multi-line control structure must be indented once, placing the first expression on the next line after the opening parenthesis.

Valid: First expression of a multi-line control structure condition block is on the line after the opening parenthesis.

while ( <em>$expr1</em> && $expr2 ) { }

Invalid: First expression of a multi-line control structure condition block is on the same line as the opening parenthesis.

while <em>($expr1</em> && $expr2 ) { }

Valid: Each line in a multi-line control structure condition block indented at least once. Default indentation is 4 spaces.

while ( <em> </em>$expr1 <em> </em>&& $expr2 ) { }

Invalid: Some lines in a multi-line control structure condition block not indented correctly.

while ( <em>$expr1</em> && $expr2 <em> && $expr3</em> ) { }
The closing parenthesis of the multi-line control structure must be on the next line after the last condition, indented to the same level as the start of the control structure.

Valid: The closing parenthesis of a multi-line control structure condition block is on the line after the last expression.

while ( $expr1 && $expr2 <em>)</em> { }

Invalid: The closing parenthesis of a multi-line control structure condition block is on the same line as the last expression.

while ( $expr1 <em>&& $expr2)</em> { }

Valid: The closing parenthesis of a multi-line control structure condition block is indented to the same level as start of the control structure.

while ( $expr1 && $expr2 <em>)</em> { }

Invalid: The closing parenthesis of a multi-line control structure condition block is not indented to the same level as start of the control structure.

while ( $expr1 && $expr2 <em> )</em> { }