Table of Contents

There has been a discussion on new coding standards for PHP5 object orientation on the Mailing list: http://thread.gmane.org/gmane.comp.bug-tracking.mantis.devel/2031/focus=2040

Coding Guidelines

First, read the PHP Coding Standard by Fredrik Kristiansen (who happens to recommend Mantis for bugtracking). The rest of this page describes in which ways we differ, as well as other Mantis-specific guidelines.

Please discuss any omissions or disagreements on our Gitter chat room, or in the Forums.

General Formatting

Comments

Code Blocks

Braces and Parentheses

Example:

while( while_condition ) {
  ... lots of code ...
  if( blah_condition ) {
    for( ... ) {
    }
    ... lots of code ...
  } # end blah if
  ... lots of code ...
 
  if( cond1 ) {
    something
  } else if( cond2 ) {
    something two
  } else {
    something else
  }
} # end while true

Conditions

To facilitate reading of complex conditions, you can either:

Switch statements

Every case must have a break or another kind of exit statement, e.g. return, die, etc. If falling through to the following case is intended, it must be documented, unless the case does not contain any code. The break is not necessary for the final, default case.

switch( condition ) {
    case 1:
        blah;
        break;
    case 2:
        blah;
        # Fall through must be commented
    case 3:        # No need for a break here
    case 4:
        blah;
        return;    # No need for a break here
    default:
        blah;
}

Miscellaneous

File Names

Always include the standard header at the top of the file.

Classes Names

Function Names

Variables Names

Prefixes

Do not use q, o, i, or l for prefixes as they are visually confusing and prone to being mistaken for each other or existing prefixes.

Counters and Loop variables

Other Variables

SQL Formatting

CSS

Tables should be wrapped a table-container:1)

<div class="table-container"><table><!-- ... --></table></div>