phpGroupWare coding Standards Please comply with the following standard when working on phpGroupWare if you want your patches accepted and modules included in supported releases. 1) Format your code so that we can read it, please! 2) Use tabs for formatting, NOT SPACES. Tabs create smaller files and editors allow developers to view a tab as however many spaces as they prefer - we use 4 spaces. Spaces do not allow this. There is one exception (see #11 below). 3) Use ' instead of " for strings, where substitutions aren't required. This is a performance issue, and prevents a lot of inconsistent coding styles. When using substitutions, use curly braces around your variables - like so: $var = "my_var: {$my_var}"; 4) Comments go on the line ABOVE the code, NOT to the right of the code, unless it is very short. 5) All functions and methods are to be documented using PhpDocumentor - http://phpdoc.org 6) Do not document every bit of code in comments. PHP is an interpreted language and it will be nasty on performance. Provide enough information for someone else to understand your code. 7) Use switch statements where many else if's are going to be used. Switch/case is faster 8) 'If' statements need to use the following format: if ( $var == 'example' ) { echo 'This is only an example'; } else { echo 'This is not a test. This is the real thing'; } Do NOT make if statements like this: if ($var == 'example'){ echo 'An example'; } OR this if($var = 'example') echo "An {$var}"; All other styles are not to be used. This is it. Use it or I will personally come and nag you to death. 9) class/function format: /** * This class is for testing * * @package phpgroupware * @subpackage module * @category testing */ class module_testing { /** * Output the value of $var the user */ public function print_to_screen() { $var = phpgw::get_var('var', 'string', 'GET'); if ( $var == 'example' ) { echo 'This is only an example'; } else { echo 'This is not a test. This is the real thing'; } } } 10) Associative arrays must be written in the following manner: $array = array ( 'var' => 'value', 'var2' => 'value2' ); Note that tabs are preferred around the '=>'. 11) Use the long format for _ to prevent clashes - and this is what createObject will expect. 16) Always use symbol based comparison operators (&&, ||) instead of text based operators (AND, OR) as they are evaluated in different orders and at different speeds. This is will prevent any confusion or strange results. 17) You code must run with E_ALL error reporting turned on, E_NOTICES are ERRORS! Where possible your code should run with E_STRICT error reporting. 18) All variables, classes, methods, functions and comments must be in English. Bad english is easier to work with than having to babelfish code to work out how it works. 19) Files should not end with an ending php tag "?>". Any whitespace after the closing tag is sent to the browser and cause errors, so don't include them. 20) If you see code which doesn't comply with the above, please fix it :) Last Updated: $Id$