Translations of this page:
  • Printable version
  • Tell by mail
  • Export to OpenOffice
  • Export to PDF
  • Export to csv
  • Export to Timeline
  • Add page to book
  • Tools:

FusionDirectory coding guidelines

Scope of style guidelines

In order to keep the code consistent, please use the following conventions.

These conventions are no judgement call on your coding abilities, but more of a style and look call.

Indentation and line length

As a basic style rule, please use 2 spaces instead of tabulators. This will remove problems when using “diff”.

For VI users, this can be achieved by the following settings:

set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=2

The line length should not exceed 80 characters. There is one exception for i18n strings that must not be split for gettext.

Performance and Readability

It is more important to be correct than to be fast.

It is more important to be maintainable than to be fast.

Fast code that is difficult to maintain is likely going to be looked down upon.


Avoid perl style comments using “#”. Always use "//" for single line comments and /* */ blocks for multi line comments.

 * This is a long comment...
 * ... which should look like this.

// Short comment

File format


UTF-8, LF 

instead of


White spaces

Use a space before affectations, around operators, before parenthesis or braces.

# Methods

# Arrays
$b = $value[0];

# Readability
if ($b + 5 > foo (bar () + 4)) {

For vars declaration, place values on the same column

var $most           = "something";
var $iHaveALongName = "value";
var $otherName      = "otherValue";

Always use spaces after comma to separate arguments:

function foo ($param1, $param2)

Always use single spaces to split logical and mathematical operations:

if ($a > 6 && $b == 17 && (foo ($b) < 1)) {


“If” statements with or without “else” clauses are formatted like this:

if ($value) {
  foo ();
  bar ();

if ($value) {
  foo ();
} else {
  bar ();

Switches are formatted like this:

switch ($reason) {
  case 'fine':

  case 'well':

Always use braces for single line blocks:

if ($value) {

Function definitions, Classes and Methods have an opening brace on the next line:

function bar ()


Always use camel casing with lowercase characters in the beginning for multi-word identifiers:

function checkForValidity ()
  $testSucceeded = false;


Non trivial variable names should speak for themselves from within the context.

// Use
$hour = 5;
// instead of
$g = 5;

Find short function names that describe what the function does - in order to make the code read like a written sentence.

if ( configReadable ("/etc/foo.conf") ) {

Use uppercase for constants/defines and _ if possible:

if ($speedUp == TRUE) {
  $wait = SHORT_WAIT;
} else {
  $wait = LONG_WAIT;

PHP specific

Use return without parenthesis

return TRUE; // good

return(TRUE); // bad

Open and close tags:

  // Something here


Do not include HTML code inside of your PHP file.

Use smarty templating if possible.

Code inclusion



instead of


GNU Indent command

Using the following

indent -bap -bad -blf -br -cdw -ce -nut -npcs -saf -sai -saw -ts2

Might be a good start, but be careful as it breaks (at least) “<?php” tag and elseif keyword.

en/documentation_dev/coding.txt · Last modified: 2014/06/27 22:16 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0