Coding Style
Basic Introduction to Osclass coding style
Coding Style
This small guide is partly based in the coding style guide of Zend Framework : http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html
PHP Code Demarcation
PHP code must always be delimited by the full-form, standard PHP tags:
Short tags are never allowed. For files containing only PHP code, the closing tag must always be omitted (See General standards).
Variables
Variables should follow the Hungarian Notation ( https://en.wikipedia.org/wiki/Hungarian_notation ), that means they should start with a character indicating the type of variable, for example i for integer, a for arrays, o for objects, s for strings ... Also, each first character of a word should be uppercase.
Note: SQL column's names should follow a similar notation, but the first character should follow an underscore. Words are separated by an underscore, all in lowercase. If the column is a primary key, it should be preceded by "pk_" if it's a foreign key by "fk_"
Classes
Class Declaration
The brace should always be written on the line underneath the class name.
Every class must have a documentation block that conforms to the PHPDocumentor standard. The following is an example of an acceptable class declaration:
Control Statements
If/Else/Elseif
Control statements based on the if
and elseif
constructs must have a single space before the opening parenthesis of the conditional and a single space after the closing parenthesis.
The opening brace is written on the same line as the conditional statement.
The closing brace is always written on its own line. Any content within the braces must be indented using four spaces.
It's required ALWAYS to put the braces.
The following if statements is not valid
Switch
Control statements written with the "switch" statement must have a single space before the opening parenthesis of the conditional statement and after the closing parenthesis.
All content within the "switch" statement must be indented using four spaces. Content under each "case" statement must be indented using an additional four spaces.
The construct default should never be omitted from a switch statement.
Documentation Format
All documentation blocks ("docblocks") must be compatible with the phpDocumentor format. Describing the phpDocumentor format is beyond the scope of this document. For more information, visit: » http://phpdoc.org/
More information
This small guide is partly based in the coding style guide of Zend Framework : http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html
Last updated