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

...

Style

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. Values true, false, and null should always be lower-case.

...

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

Class names should be CamelCased. Only a single class should appear in a file. Class file names should be lowercase and use underscores to separate words.

Warning
titleIncorrect
Code Block
languagephp
titlemy_class.php
linenumberstrue
<?php
class myClass {
}
?>
Tip
titlecorrect
Code Block
languagephp
titlemy_class.php
linenumberstrue
<?php 
class MyClass {
}
?>

 

Methods

Comments

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

...