<<toc></toc>>
This page covers some of the basics of the Flourish code standards.
This page is a work-in-progress and thus very incomplete.
All PHP files should start with a long PHP tag `omit the closing PHP tag `?>`.
Closing PHP tags are omitted because they are unnecessary and if they have any white-space after them, can prevent the modification of headers since output has already begun. In addition, files should never leave PHP and go to raw output, so the closing PHP tag should never be present. If output is required, the `echo` statement should be used instead.
This is incorrect:
Short tags `
This is incorrect:
In general lines should try not to exceed 80 characters in length, however this does happen a fair amount. Use best judgment about how the code will be most readable.
All files should be saved in Unix format, meaning that each line should end with a single line feed (also known as an LF or `\n`).
All code should be indented from the left margin by tab characters and a tab width should be set to 4 spaces. All indenting done in the middle of a line should be with spaces.
Please note that these code samples have all tabs replaced by 4 spaces because browsers default to 8 spaces per tab and the code highlighter automatically converts the tabs to spaces for proper spacing.
Large blocks of assignments should have the operators lined up.
All blocks of code, such as `if`, `function`, `switch`, `class` should have the contents indented one level. `switch` statements should have the `case` block contents indented another level:
Long arrays without explicit keys and most arrays with explicit keys should have one entry per line, indented one level from the line containing the beginning of the array. When array contents are indented, all double arrows (`=>`) should be lined up with spaces.
All classes and methods should have the opening and closing braces on their own line.
The opening brace should not be on the same line as the class or method name.
This is incorrect:
All flow-control code blocks, including `if`, `while`, `for`, `foreach`, `switch`, etc. should have the opening brace on the same line as the beginning of the statement.
This is incorrect:
All flow-control code block should also have a single space after the statement name before the `(` or `{`. `else` statements should have a space before and after the word. `else/if` statements should be written as `elseif`, not `else if`.
All classes are written in `UpperCamelCase`, methods are writen in `lowerCamelCase`, members are written in `lower_underscore_notation` and constants are written in `UPPER_UNDERSCORE_NOTATION`.
All variables are written in lower_underscore_notation.
Acronyms in class, method and constant names are written as all uppercase. Acronyms in members and variables are written as all lowercase.