PHP Code Style Guide ==================== This is the Code Style guide for PHP. See the :doc:`main page ` for general guidelines and guides specific to other languages. Assume we're using `the Drupal PHP coding style `_ unless otherwise noted here. Always use to delimit PHP code, not the shorthand, `_ when appropriate. - Explicitly declare `visibility `_ (public, private, protected) for member variables and methods. - Do **NOT** use PHP closing tags for files that contain only PHP code: The ?> at the end of code files is purposely omitted. This includes for module and include files. … Removing it eliminates the possibility for unwanted whitespace at the end of files which can cause “header already sent” errors, XHTML/XML validation issues, and other problems. Maximum Line Length: 120 characters ----------------------------------- The maximum length of any line of code is 120 characters, unless it contains a string that cannot have a break in it. (This differs from Drupal's 80-character maximum length.) Tip: If you're using Eclipse, add a ruler to the 120 mark to see where you should break to the next line. See [[Developer Guide: Setting Up Eclipse PDT]] for how. Include Docblocks on All New Code --------------------------------- ThinkUp uses PHPDocumentor to ease code maintenance and `auto-generate class documentation `_. Include PHPDoc-style “docblocks” in all of your PHP code. When writing your documentation, please use `PHPDocumentor's syntax `_. Keyword case ------------ Drupal style guide states use of uppercase value keywords (TRUE, FALSE, NULL), ThinkUp user lowercase. Same-line Curly Braces ---------------------- Unlike Drupal's style guide, ThinkUp keeps opening and closing curly braces on the same line as the control keyword (if, else). MVC Architecture ---------------- ThinkUp implements the :doc:`Model-View-Controller ` design pattern. All new PHP code should follow suit. Read more about ThinkUp's :doc:`MVC implementation `. Drupal conventions to take notice of ------------------------------------ Some of these are inherited from PEAR: * When constructing multi line IFs, the boolean operator should be at the beginning of the line, not the end.