Child pages
  • Coding Standards

Versions Compared

Key

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

...

Table of Contents
maxLevel2

Coding Standard

Summary

PHP

Variable names

  1. Corresponding to data from databases: $my_var.
  2. Corresponding to algorithm: $my_var.
  3. The visibility of a member variable does not affect its name: private $my_var.

...

  1. The visibility must be defined every time, even when it is a public method.
  2. The order of the method properties should be: visibility static function functionName().

    Code Block
    borderStylesolid
    private static function foo()
    

...

  1. Method and function names always use CamelCase: begin with a lowercase character and each following words must begin with an uppercase character.

    Code Block
    borderStylesolid
    public function myExampleMethodWithALotOfWordsInItsName()
    
  2. Braces introducing method code have to be preceded by a carriage return.

    Code Block
    borderStylesolid
    public function myMethod($arg1, $arg2)
    {
    	...
    }
    
  3. Method and function names must be explicit, so function names such as b() or ef()are completely forbidden.

    Info
    titleExceptions

    The only exceptions are the translation function (called l()) and the debug the functions (named p() and d()).

...

  1. Inside functions and methods, only the "//" comment tag is allowed.
  2. After the "//" comment marker, a space is required: // Comment.

    Code Block
    borderStylesolid
    // My great comment
    
  3. The "//" comment marker is tolerated at the end of a code line.

    Code Block
    borderStylesolid
    $a = 17 + 23; // A comment inside my example function
    
  4. Outside of functions and methods, only the "/" and "/" comment markers are allowed.

    Code Block
    borderStylesolid
    /* This method is required for compatibility issues */
    public function foo()
    {
    	// Some code explanation right here
    	...
    }
    
  5. PHP Doc comment block is required before the declaration of the method.

    Code Block
    borderStylesolid
    /**
     * Return field value if possible (both classical and multilingual fields)
     *
     * Case 1: Return value if present in $_POST / $_GET
     * Case 2: Return object value
     *
     * @param object $obj Object
     * @param string $key Field name
     * @param integer $id_lang Language id (optional)
     * @return string
     */
    protected function getFieldValue($obj, $key, $id_lang = NULL)
    
    Info
    titleFor more informations

    For more informations information about the PHP Doc syntax: http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.pkg.html

...

  1. The return statement does not need brackets, except when it deals with a composed expression.

    Code Block
    borderStylesolid
    return $result;
    return ($a + $b);
    return (a() - b());
    return true;
    
  2. The return statement can be used to break out of a function.

    Code Block
    borderStylesolid
    return;
    

Call

Function Performing a function call preceded by a "@" is forbidden, but beware with of function/method call with login/password or path arguments.

...