Please follow the following guidelines when contributing code to FCMS. Some of the current code for FCMS was written prior to these guidelines. We are working to fix existing code to meet these guidelines.
PHP Code Tags
You should always use the full php open tag, never use short open tags.?>
Code Indenting
Please use tabs instead of spaces when indenting your code. If you are using a text editor please set your tabs to equal 4 spaces.Naming Variables, Classes and Functions
Variables, Classes and Functions can only contain alphanumeric characters, no underscores or spaces, and must alwasy start with a lowercase letter. Please use "Camel Case∞" (start each word with a Capital letter, except the first one).
Right
$myVariable = 5;
getLatestPhotos()
Wrong
$myvariable = 5;
get_latest_photos()
Comments
For one or two line comments please use // instead of /* */
Right
// this is comment line one
// this is comment line two
Wrong
/* this is comment line one */
/* this is comment line two */
At the beginning of each function please use the following block style comments
* Function Name
*
* Description of what the
* function does, including any
* variables
*/
Parentheses
Opening parentheses for conditional statements, functions and clases should start on the same line. Do not put opening parentheses on their own line.
Right
if ($house > $car) {
echo "All is right with the world";
} else {
echo "Something's wrong here";
}
Wrong
if ($house > $car)
{
echo "All is right with the world";
}
else
{
echo "Something's wrong here";
}
Strings
For Strings without variables (literal Strings), apostrophes or single quotes, always use single quotes. For all other Strings, use double quotes.
Right
$literalString = 'This is a string';
$containsSingle = "I can't read";
$myString = "You have $money dollars.";
Wrong
$literalString = "This is a string";
$containsSingle = 'I can\'t read';
$myString = 'You have ' . $money . 'dollars.';
When concatenating Strings using the "." operator, always use a space between String segments.
When concatenating Strings on multiple lines, always line things up.
FROM `employee`
WHERE `id` = 5";
Functions
When calling a function, do not use a space before lising the function arguments. You should also put a space after the comma seperating the arguments.getLatestPhotos()
When defining a function, always use a space before listing the function arguments.
... some code
}
SQL
Always use all caps for SQL keywords, and use apostrophes for table names and fields.
Right
SELECT `id`, `name` FROM `employee` WHERE `name` LIKE 'a%' ORDER BY `id`
Wrong
select id, name from employee where name like 'a%' order by id
