2004-12-11 03:42:43 +00:00
|
|
|
WineHQ Application Database Coding Practice
|
|
|
|
|
|
2006-06-26 17:25:19 +00:00
|
|
|
/**
|
|
|
|
|
* HTML
|
|
|
|
|
*/
|
2004-12-11 03:42:43 +00:00
|
|
|
- Respect html coding standards. The current doctype is HTML 4.01 transitional (http://www.w3.org/TR/REC-html40/)
|
|
|
|
|
Try to make your content validate nicely (http://validator.w3.org/)
|
|
|
|
|
|
2008-02-23 12:06:24 +11:00
|
|
|
Avoid using implicitly closed elements eg. <br/> in HTML 4.01 transitional, as it can lead to validation errors.
|
|
|
|
|
http://www.w3.org/TR/html401/struct/text.html#edef-BR
|
2004-12-11 03:42:43 +00:00
|
|
|
|
2006-06-26 17:25:19 +00:00
|
|
|
/**
|
|
|
|
|
* Variables naming
|
|
|
|
|
*/
|
2005-01-31 01:49:27 +00:00
|
|
|
variables that don't come from outside your script (i.e. that aren't fetched from superglobals) should be named this way
|
|
|
|
|
(a.k.a hungarian notation):
|
|
|
|
|
prefix + var_name
|
|
|
|
|
|
|
|
|
|
Where prefix is one of:
|
|
|
|
|
Scalar types:
|
|
|
|
|
i for integers
|
|
|
|
|
f for floats
|
|
|
|
|
s for strings
|
2006-06-28 17:21:58 +00:00
|
|
|
sh for html strings
|
2005-01-31 01:49:27 +00:00
|
|
|
b for booleans
|
|
|
|
|
Compound types:
|
|
|
|
|
a for arrays
|
|
|
|
|
o for objects
|
|
|
|
|
Special type:
|
|
|
|
|
h for handles
|
|
|
|
|
|
|
|
|
|
the rest of the variable's name is using camel style
|
|
|
|
|
examples:
|
|
|
|
|
$aUsers
|
|
|
|
|
$iTopicId
|
|
|
|
|
$hRecordSet
|
|
|
|
|
$sQuery
|
|
|
|
|
$hResult
|
|
|
|
|
|
|
|
|
|
|
2006-06-26 17:25:19 +00:00
|
|
|
/**
|
|
|
|
|
* Functions naming
|
|
|
|
|
*/
|
2006-06-28 17:21:58 +00:00
|
|
|
1)functions name should be declarative and be prefixed with the name of the module (=file) where it is stored (for example image_show_thumbnail())
|
2005-01-31 01:49:27 +00:00
|
|
|
2)methods (functions inside a class) are named like this: setMyName() (i.e. words separated with an upper case character)
|
|
|
|
|
3)normal functions (outside a class) are named like this: query_appdb() (i.e. words separated with an underscore)
|
|
|
|
|
|
|
|
|
|
|
2006-06-26 17:25:19 +00:00
|
|
|
/**
|
|
|
|
|
* general coding guidelines
|
|
|
|
|
*/
|
2005-01-31 01:49:27 +00:00
|
|
|
1) functions, loops and if's are written this way (look at the way {}'s are lined up):
|
2005-01-10 22:13:47 +00:00
|
|
|
<?php
|
2006-06-26 17:25:19 +00:00
|
|
|
function do_foo($sVar)
|
2004-12-11 03:42:43 +00:00
|
|
|
{
|
2006-06-26 17:25:19 +00:00
|
|
|
if(isset($sVar))
|
2004-12-11 03:42:43 +00:00
|
|
|
{
|
|
|
|
|
echo "bar";
|
2005-01-31 01:49:27 +00:00
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
echo "foo";
|
|
|
|
|
}
|
2004-12-11 03:42:43 +00:00
|
|
|
}
|
|
|
|
|
?>
|
|
|
|
|
|
2005-01-31 01:49:27 +00:00
|
|
|
2) indentation is made of 4 spaces (no tabs please)
|
2004-12-11 03:42:43 +00:00
|
|
|
|
2005-01-31 01:49:27 +00:00
|
|
|
3) line length should be no more than 130 characters, preferably < 80
|
2004-12-11 03:42:43 +00:00
|
|
|
|
2006-06-26 17:25:19 +00:00
|
|
|
4) use long php tags (<?php ?>) instead of short ones (<? ?>) as :
|
|
|
|
|
a) it could be removed from future versions of php
|
|
|
|
|
b) if conflicts with tags like <?xml version=1.0 ?> that are used in xhtml
|
|
|
|
|
|
|
|
|
|
5) do not use vars that require register_globals to be on as:
|
|
|
|
|
a) it is off by default in php 4.1+
|
|
|
|
|
b) it is more secure
|
2008-06-26 12:07:29 -04:00
|
|
|
c) it makes it easier to understand where your vars are coming from (forms, session, etc.)
|
2006-06-26 17:25:19 +00:00
|
|
|
|
2004-12-11 03:42:43 +00:00
|
|
|
|
2006-06-26 17:25:19 +00:00
|
|
|
/**
|
|
|
|
|
* comments
|
|
|
|
|
*/
|
|
|
|
|
1) function, method, header and multiline comments:
|
2004-12-11 03:42:43 +00:00
|
|
|
/**
|
|
|
|
|
* This functions does nothing interesing.
|
|
|
|
|
* More comments to come here...
|
|
|
|
|
*/
|
|
|
|
|
function bar()
|
|
|
|
|
{
|
|
|
|
|
foo();
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-26 17:25:19 +00:00
|
|
|
2) one-line comments
|
|
|
|
|
// This is a one line comment
|
2004-12-11 03:42:43 +00:00
|
|
|
|
2006-06-26 17:25:19 +00:00
|
|
|
3) always put a single space after the comment mark
|
2004-12-29 03:38:37 +00:00
|
|
|
|
2006-06-26 17:25:19 +00:00
|
|
|
4) never use # for commenting as it will become obsolete in the future
|
2007-11-23 22:18:36 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* string quotes
|
|
|
|
|
*/
|
|
|
|
|
There are two different ways to quote strings in PHP - single quotes or double quotes.
|
|
|
|
|
The difference is that the parser does variable interpolation in double-quoted strings, but not in single quoted strings.
|
|
|
|
|
Because of this, always use single quotes unless the string contains a variable that needs to be parsed.
|
|
|
|
|
|
|
|
|
|
Also if the string contains a variable put it inside double quotes instead of using 'bla' . $var . 'bla';
|
|
|
|
|
To increase readability of the code.
|
|
|
|
|
Wrong:
|
|
|
|
|
$str = "This is a long string without any variables";
|
|
|
|
|
$str = 'This string contains a variable ' . $var . ' enough said.';
|
|
|
|
|
|
|
|
|
|
Right:
|
|
|
|
|
$str = 'This is a long string without any variables';
|
|
|
|
|
$str = "This string contains a variable $var enough said";
|