...
Tabs should always be used for indentation. Spaces should never be used for indentation. We live in a world where IDEs can be configured to display tabs at variable lengths, so configure your tab width to what you feel comfortable with. This author prefers tabs to be represented as 4 spaces.
Line Length
Lines should be designed such that a reader can avoid horizontal scrolling, except in cases where scrolling offers improved readability over word-wrapping. As the resolution and width of monitors has increased the standard width of 80 characters (previously the width of a punch card) no longer holds any relevance. Use your best judgement to determine where lines should wrap.
...
Tip |
---|
|
Code Block |
---|
| define("MY_CONSTANT", "some value"); |
|
Conditionals
...
Statements
Blesta uses Compact Control Readability style. Each statement should begin on its own line.
Tip |
---|
|
Code Block |
---|
| if ($foo > $bar) {
echo "foo is greater";
}
else {
echo "bar is greater";
} |
|
Classes
Methods
...
There are three types of comments that may be used in PHP. They are block comments (/* */), inline comments (//), and shell comments (#).
Inline comments should be used to clarify code. You are discouraged from using inline comments at the end of a line as this creates run-on lines and your comment is unlikely to be read.
Note |
---|
title | Correct, but discouraged |
---|
|
Code Block |
---|
|
$c = 2*pi()*$r; // Calculate the circumference |
|
Tip |
---|
|
Code Block |
---|
| // Calculate the circumference
$c = 2*pi()*$r; |
|
These comments should only be used to identify TODO comments.
Code Block |
---|
language | php |
---|
title | A TODO Comment |
---|
firstline | 1 |
---|
linenumbers | true |
---|
|
<?php
class MyClass {
#
# TODO: Finish this class.
#
}
?> |