Elgg Core and Plugin Coding Standards: Revision

Last updated by Brett
  1. Unix style line endings
  2. Hard tabs, 4 chars.
  3. No shortcut tags ( <? or <?= or <% )
  4. PHPDoc comments on functions and classes (including methods and declared members).
  5. {}s mandatory around any code block > 1 line or statement: 
  6. Die in a fire:
    if (true) foreach($arr as $elem) echo $elem;
    Bad:
    if (true)
    foreach($arr as $elem)
    echo $elem;

    Good:
    if (true) {
    foreach($arr as $elem)
    echo $elem;
    }

    Great:
    if (true) {
    foreach($arr as $elem) {
    echo $elem;
    }
    }
  7. Functions named using underscore_character().
  8. Classes named using CamelCase()
  9. Globals and constants in ALL_CAPS (FALSE, TRUE, NULL, ACCESS_FRIENDS, $CONFIG).
  10. function_spaced($like_this, $and_this)
  11. Keywords spaced like this: if (false) { ... }
  12. Private methods don't need a preceding _
  13. When using variables in strings, include with double quotes instead of concatenating (eg echo "Hello, $name!"; vs echo 'Hello, ' . $name . '!  How are you?';
  14. Line lengths should be reasonable.  If you are writing lines over 120 characters, please revise the code.
  15. Preferred no closing ?> tag. (Avoids problems with trailing whitespace.)
  16. Avoid hash-style comments: // and /* */ preferred.

History