Skip to content
Spuds edited this page Jan 26, 2023 · 7 revisions

DEVELOPER DOCUMENTATION > CODING STANDARDS

Coding Standards

Naming Conventions

  • Naming class names should be PascalCase format.
  • Private functions and variables should start with a _ i.e. private _foo_bar()
  • Function names and variables may use either delimiter_separated_words or caseSeparated words
  • The name of the variable or function should describe what it is or does. i.e. $message_settings not $mset
  • The name of the function or method should signify what the object is being used for, not where it is to be used, $action_save

Autoloading (starting with 2.0)

General

  • Use the Allman indentation style.
  • Use tabs to indent code, not spaces.
  • Try to always use brackets, even with one line of code after a control structure.
  • No space after function name and before (); i.e. fooBar($var1, $var2);
  • Space before and after the equal sign. i.e. $var = '';
  • Each statement should be on its own line.
  • One space after control structures such as if () elseif () for () while () etc.
  • One space after language constructs such as echo, list, etc.
  • Comma separated argument lists must have a space after the comma.
  • When declaring a function, the function name should not have a space after it. i.e. function foobar($var1, $var2 = '').
  • One space before and after the period ‘.’ when concatenating.
  • Use comma ‘,’ concatenation for language constructs i.e. echo 'foo ', $txt['bar'], ' is great'
  • Use strict equality checks === instead of == wherever practical.
  • You should avoid the use of @ to silence an error.
  • Use single quotes, reserve double quotes for when you want to concatenate a variable or use control characters.

File Syntax

  • PHP files must start with
  • Files must be saved in Unix Style line ending as UTF-8 (w/o byte order mark / ANSI as UTF-8)
  • No whitespace at the end of lines.
  • Empty lines mean that, avoid hidden spaces and indentation tabs in them.

Functions (and language constructs)

  • Arguments with default values go at the end of the argument list. i.e. function foobar($var1, $var2 = '')
  • Use isset() instead of in_array()
  • Use include_once() instead of include() and require_once() instead of require().

Variables

  • Initialize all variables.
  • Constants must be in uppercase.
  • It is generally best to use an associative array instead of numeric.
  • Avoid internal type changing/conflicts, $var = '0' is not $var = 0;

Comments

  • Commenting functions and classes use /** ... */ with the appropriate PHPDoc tags.
  • For inline comments use //, Multiple line comments may use /* */ and each are on their own line.
  • Comment often and use them to describe a block of code or as a placeholder for future code/mods.
  • Comments should be unique per the file and should try to be unique per the entire application.
  • Comments should be kept under 80 characters per line.

HOME > TECH GUIDES

Architecture

Functions and Variables

  • About $user_info variable
  • About the createList() function.
  • About [Template Layers](Template layers).
  • About [is_activated](is activated) values.

Customization

  • [Create a theme](Make a new theme)
  • [Create an Addon](Create an Addon)

GitHub

Clone this wiki locally