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 are ALL_CAPS.
  10. function_spaced($like_this, $and_this)
  11. Keywords spaced like this: if (false) { ... }
  12. Private methods don't need a preceding _
  13. Constants in caps (FALSE, TRUE, NULL, ACCESS_FRIENDS)
  14. Use single quotes for text without vars; double quotes for text with vars. (eg echo 'Hello!  How are you?'; vs echo "Hello, $name!  How are you?";
  15. Line lengths should be reasonable.  If you are writing lines over 120 characters, please revise the code.
  16. Preferred no closing ?> tag. (Avoids problems with trailing whitespace.)
  17. Preferred C-style comments (slashes)

History