...
All PHP files should be encoded using UTF-8, with no byte-order-mark (BOM).
Programming Styles
Variables
Use logical and descriptive names for your variables. Variables used in iterating loops, such as $i, $j, $k, etc., are exceptions to this rule. Variables should contain only lower-case letters, underscores, and numbers, and should start with a letter.
Warning |
---|
|
Code Block |
---|
| $foo = 365; // not descriptive
$days_in_non_leap_year = 365; // too long
$_year_days = 365; // starts with an underscore |
|
Tip |
---|
|
Code Block |
---|
| $year_days = 365;
$leap_year_days = 366; |
|
Strings
Literals
Strings consisting of more than one character should be surrounded with double-quotes ("). Strings consisting of only a single character may be surrounded with single-quotes (').
...
Tip |
---|
|
Code Block |
---|
| define("MY_CONSTANT", "some value"); |
|
Keywords
Keywords should always be lower-cased. This is so they do not conflict with constants.
Statements
Blesta uses Compact Control Readability style. Each statement should begin on its own line. The exception to this rule is do-while.
Tip |
---|
|
Code Block |
---|
| if ($foo > $bar) {
echo "foo is greater";
}
else {
echo "bar is greater";
}
$i = 5;
do {
echo $i--;
} |
|
...
Classes
Methods
There are three types of comments that may be used in PHP. They are block comments (/* */), inline comments (//), and shell comments (#).
...
Tip |
---|
|
Code Block |
---|
language | php | title | A TODO Comment |
---|
firstline | 1 |
---|
linenumbers | true |
---|
| <?php
class MyClass {
#
# TODO: Finish this class.
#
}
?> |
|