Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
titleIncorrect
Code Block
languagephp
$foo = 365; // not descriptive
$days_in_non_leap_year = 365; // too long
$_year_days = 365; // starts with an underscore
Tip
titleCorrect
Code Block
languagephp
$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
titleCorrect
Code Block
languagephp
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
titleCorrect
Code Block
languagephp
if ($foo > $bar) {
    echo "foo is greater";
}
else {
    echo "bar is greater";
}

$i = 5;
do {
    echo $i--;
}

...

 while ($i > 0);

Classes

Methods

Comments

There are three types of comments that may be used in PHP. They are block comments (/* */), inline comments (//), and shell comments (#).

...

Tip
titleCorrect
Code Block
languagephptitleA TODO Comment
firstline1
linenumberstrue
<?php
class MyClass {
    #
    # TODO: Finish this class.
    #
}
?>