Switch Declaration

Case and default keywords must be lowercase.

Valid: Keywords in lowercase.

switch ($foo) { <em>case</em> 'bar': break; <em>default</em>: break; }

Invalid: Keywords not in lowercase.

switch ($foo) { <em>CASE</em> 'bar': break; <em>Default</em>: break; }
Case statements must be followed by exactly one space.

Valid: Case statement followed by one space.

switch ($foo) { case<em> </em>'bar': break; }

Invalid: Case statement not followed by one space.

switch ($foo) { case<em></em>'bar': break; }
There must be no whitespace between the case value or default keyword and the colon.

Valid: Colons not preceded by whitespace.

switch ($foo) { case 'bar'<em></em>: break; default<em></em>: break; }

Invalid: Colons preceded by whitespace.

switch ($foo) { case 'bar'<em> </em>: break; default<em> </em>: break; }
The case or default body must start on the line following the statement.

Valid: Body starts on the next line.

switch ($foo) { case 'bar': <em></em> break; }

Invalid: Body on the same line as the case statement.

switch ($foo) { case 'bar':<em></em> break; }
Terminating statements must be on a line by themselves.

Valid: Terminating statement on its own line.

switch ($foo) { case 'bar': echo $foo; <em>return;</em> }

Invalid: Terminating statement not on its own line.

switch ($foo) { case 'bar': <em>echo $foo; return;</em> }
Terminating statements must be indented four more spaces from the case statement.

Valid: Break statement indented correctly.

switch ($foo) { case 'bar': <em> </em>break; }

Invalid: Break statement not indented four spaces.

switch ($foo) { case 'bar': <em> </em>break; }
Case and default statements must be defined using a colon.

Valid: Using a colon for case and default statements.

switch ($foo) { case 'bar'<em>:</em> break; default<em>:</em> break; }

Invalid: Using a semi-colon or colon followed by braces.

switch ($foo) { case 'bar'<em>;</em> break; default: <em>{</em> break; <em>}</em> }
There must be a comment when fall-through is intentional in a non-empty case body.

Valid: Comment marking intentional fall-through in a non-empty case body.

switch ($foo) { case 'bar': echo $foo; <em>// no break</em> default: break; }

Invalid: No comment marking intentional fall-through in a non-empty case body.

switch ($foo) { case 'bar': echo $foo;<em></em> default: break; }