This repository has been archived by the owner on Jan 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Dev CodingGuidelines ControlStructures
Frank Kleine edited this page Apr 7, 2012
·
1 revision
Keyword and condition are separated by a space. Declarations within an if block are always enclosed in parenthesis even if it consists only of one line.
{| border=1 class="simple" ! (condition2)) { |} action1; } elseif ((condition3) && (condition4)) { action2; } else { defaultaction; }
Conditions should always be verbose:
if (in_array($foo, $baz) === true) { ... }
It is encouraged to write non-changeable statements on the left side of a comparison:
if (null === $foo) { ... }
This helps to make clear that a comparison is achieved and no assignment should be done.
The switch/case block follows the same rules:
switch (condition) { case 1: action1; break; case 2: action2; // break omitted default: defaultaction; break; }
The default block is always the last block of the statement, the break declaration within the default block is optional. If the break statement is omitted it must contain an inline comment in exactly the same way as above to exclude the notion of a bug.
Next: Statements