Versions Compared

Key

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

...

Class names should be CamelCased. Only a single class should appear in a file. Class file names should correlate to the class name, be lowercase, and use underscores to separate words. Class constructors should be named using the __construct() magic method.

Warning
titleIncorrect
Code Block
languagephp
titlemy_class.php
linenumberstrue
<?php
// Class name starts with a lower case letter
class myClass {
    // Constructor should be named __construct()
    public function myClass() {
    }
}
?>
Tip
titlecorrect
Code Block
languagephp
titlemy_class.php
linenumberstrue
<?php 
class MyClass {
    public function __construct() {
    }
}
?>

 

Methods

Method names should begin with a lowercase letter and be camelCased. Type hinting should be used whenever possible, but must conform to PHP 5.1 syntax (i.e. only objects and arrays may be defined using type hints).

...

Tip
titleCorrect
Code Block
languagephp
/**
 * This is a doc DocBlockblock comment 
 */ 
function foo() {

}

...