Home Credits Demo Documentation Download FAQ

Documentation > Coding Standards

Coding Standards

We established the standards below in order to keep ourselves sane and the code as readable as possible. While collaborating on the implementation we found that each one of us had a slightly different code formatting style which made the code ugly and often harder to follow. Here are the guidelines we agreed on... not unbreakable rules :)







Special Conventions

Hungarian Notation for Variable Names

Add letters to indicate type followed by the name of the variable.


Add the following letters after the scope letter to indicate the type:

Some Examples

Prefix Notation for Methods/Functions

Add a prefix to indicate the method's/function's purpose followed by the name of the method/function.


Add the following prefixes to indicate the method/function's purpose:

Some Examples



Use spaces around keywords (if, for, else, etc), operators (==, !=, <, etc), and commas and semicolons.

Line Length

Limit the length of lines to 80 characters.


Place the starting brace at the end of the line and indent the body as in the following example:

if ($condition) {
    body . . .

Also always use braces even if they are technically optional as in the following example

if ($condition) {
    echo 'condition is true';


Use single quotes to reference the elements of an array and for strings.

Use double quotes only when necessary

Commas and Periods

Use commas for outputting multiple items in echo statements


Documenting Classes, Methods, Functions

phpDocumentor ( generates documentation for php code in a fashion similar to Javadocs. Create a comment block before each class, method, or function. The first part of the block is a brief description that is terminated by either a period or a blank line. The second part is a long description that is also terminated by a blank line. The third part is composed of tags.

The following tag is required:

The following tags are optional:

The following is an example comment block:

* Finds all employees in a department
* Generates and executes a SQL query based on the
* department ID that is passed in as a parameter. The query
* searches a database to locate all employees in the department.
* @author Jonathan Howarth
* @return array   a recordset for successful queries or an integer error
*                 code for unsuccessful queries
function doEmployeeLookupByDepartment($iDepartmentId) {
    . . .

Inline Documentation

Inline documentation should be placed on the line before the code to which it refers as illustrated in the following example:

// cycles through all employees in one department
for ($i = 0; $i < $result->numRows(); $i++) {
    $aEmployee = $result->fetchRow(DB_FETCHMODE_ASSOC, $i);
    echo $aEmployee['firstName'].$aEmployee['lastName'];


Use the following words to provide additional comments to the code:

HTML Conventions

Write all HTML tags in lower case.

<a href="">Virginia Tech</a>

Use 2 spaces to indent tags.

    more html code . . .

Write an entire php page inside of one set of php tags. In other words, do not close the <?php . . . ?> tag to write HTML. Instead use the following echo command:

php code . . .
echo <<<END
    This uses the "here document" syntax to output multiple lines
    with $variable interpolation. Note that the here document terminator
    must appear on a line with just a semicolon no extra whitespace!
php code . . .

File Naming conventions

PHP escaping
Last modified: September 13, 2004
You are visitor number 1 since May. 22, 2018.

web hosting kindly provided by Logo