Programming Standards
Good programming is clear, unambiguous programming. Let's run through a few tips to help make your code more readable, easier to debug, and easier to make changes to later on.
Braces
For clarity each brace should be placed on its own line in the code:
if ($condition) { // code goes here }
Don't be tempted to condense code like this:
if ($condition) { // code goes here }
Indenting
Indent code between braces:
if ($condition) { // code goes here }
Code between braces within braces should have deeper indenting:
if ($condition) { if ($condition2) { // code goes here } // some more code goes here }
Give Operators Space
All operators (except --
and ++)
should have a space either side.
$a = $b + $c;
String Quoting
All strings should be quoted with single quotes when they don't contain variables or control characters. Otherwise always use double quotes:
$a = 'Hello, World!'; $b = "Hello,\nWorld!"; $c = "$hello,\nWorld!";
Return Values
Use only lower-case true
and false
for return values...