Elgg Core and Plugin Coding Standards: Revision

Last updated by Brett
  1. Unix style line endings
  2. Hard tabs, 4 character tab spacing.
  3. No shortcut tags ( <? or <?= or <% )
  4. PHPDoc comments on functions and classes (including methods and declared members).
  5. Mandatory wrapped {}s around any code blocks.
  6. Bad:
    if (true)
    foreach($arr as $elem)
    echo $elem;
    Good:
    if (true) {
    foreach($arr as $elem) {
    echo $elem;
    }
    }
  7. Name functions and methods using underscore_character().
  8. Name classes using CamelCase()
  9. Name globals and constants in ALL_CAPS (FALSE, TRUE, NULL, ACCESS_FRIENDS, $CONFIG).
  10. Space functions like_this($required, $optional = TRUE)
  11. Space keywords and constructs like this: if (false) { ... }
  12. Include variables in strings with double quotes instead of concatenating (eg echo "Hello, $name!  How are you?"; vs echo 'Hello, ' . $name . '!  How are you?';
  13. Line lengths should be reasonable.  If you are writing lines over 100 characters, please revise the code.
  14. Use slash-style comments. (// and /* */)
  15. Preferred no closing ?> tag at EOF. (Avoids problems with trailing whitespace.)

History