phpClick
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 :)

Naming

Capitalization

Classes

Variables

Methods/Functions

Constants

Special Conventions

Hungarian Notation for Variable Names

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

Type

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.

Prefixes

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

Some Examples

Indentation

Spaces

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

Line Length

Limit the length of lines to 80 characters.

Braces

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';
}

Quotes

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

Documentation

Documenting Classes, Methods, Functions

phpDocumentor (http://www.phpdoc.org/) 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'];
}

Notifications

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

HTML Conventions

Write all HTML tags in lower case.

<a href="www.vt.edu">Virginia Tech</a>

Use 2 spaces to indent tags.

<table>
  <tr>
    <td>
    more html code . . .
    </td>
  </tr>
</table>

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
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!
END;
php code . . .
?>

File Naming conventions

PHP escaping





http://phpclick.sourceforge.net/
Last modified: September 13, 2004
You are visitor number 1 since May. 24, 2017.

web hosting kindly provided by SourceForge.net Logo