Coding Standards
These are my personal coding standards. For the most part they are based around to key features:
- Features of editors I've used (code folding)
- Tab-based indenting - this allows each developer to set the indent to their preferred amount.
- Zend Framework required coding standards
- Anything beginning with an underscore is internal to whatever framework / library I'm using, and to be avoided.
PHP Tags
PHP open tags are always long for (<?php as opposed to <? or <?= )
Indenting and Spacing
Indenting is tab-based.
Extra spacing beyond indenting should not be used (eg. for ligning up = signs).
Indenting a run-on line with anything but a tab is stupid.
Line Length
Word-wrap, hi-resolution screens and graphical editors make maximum line length limits obsolete. Developers are free to insert extra line returns for readability.
Function Naming
Global Scope
Underscores are used in place of spacing. Camel-case is not used.
Class Methods
Class methods use camel-case. Underscores are not to be used at all. No special naming conventions are applied to private or protected methods.
Class Member Naming
Class member variables must begin with "m_". This clearly denotes the difference between methods and members.
Curly Braces
The opening curly brace should appear on the same line as the statement it belongs to. This reduces folded code size and some editors will show this line on long code blocks allowing for easy brace matching.
Code inside curly braces should be indented by 1 level. Code inside curly braces should never appear on the same line.
Switch Blocks
In addition to the above, each block of case statements should be separated by an extra line return.
Code related to each case should be indented by 1 level.
Example:
switch ($foo) {
case ONE:
case TWO:
// Code here
case THREE:
// Code here
default:
// Code here
}