Developing/Codestyle

From Observium

Jump to: navigation, search

Contents

Indenting and spacing

  • 2 spaces. No tabs!

Blocks

  • { and } are on separate lines, unless the content is only one statement.
  • For/while/if/foreach are always surrounded by {}, even if they are only executing one statement.

Formatting

  • One space between for/if/foreach/while and the following opening bracket.
  • Empty line between the "global" line and the rest of the code in a function.
  • Empty line between the final "return" statement and the rest of the code in a function.
  • Parameters to "echo" always between brackets, even if PHP does not require it.
  • No trailing spaces on any line!

Optimization

  • Use internal caching functions as much as possible.

PHP tags

  • No short tags, always use the full <?php instead of <? and <?php echo($foo); ?> instead of <?= $foo ?>.

Shebang

  • For command-line executable scripts, use /usr/bin/env instead of a direct path to the php interpreter binary.