...
Table of Contents | ||
---|---|---|
|
Coding Standard
Summary
PHP
Variable names
- Corresponding to data from databases:
$my_var
. - Corresponding to algorithm:
$my_var
. - The visibility of a member variable does not affect its name:
private $my_var
.
...
- The visibility must be defined every time, even when it is a public method.
The order of the method properties should be:
visibility static function functionName()
.Code Block borderStyle solid private static function foo()
...
Method and function names always use CamelCase: begin with a lowercase character and each following words must begin with an uppercase character.
Code Block borderStyle solid public function myExampleMethodWithALotOfWordsInItsName()
Braces introducing method code have to be preceded by a carriage return.
Code Block borderStyle solid public function myMethod($arg1, $arg2) { ... }
Method and function names must be explicit, so function names such as
b()
oref()
are completely forbidden.Info title Exceptions The only exceptions are the translation function (called
l()
) and the debug the functions (namedp()
andd()
).
...
- Inside functions and methods, only the "
//
" comment tag is allowed. After the "
//
" comment marker, a space is required:// Comment
.Code Block borderStyle solid // My great comment
The "
//
" comment marker is tolerated at the end of a code line.Code Block borderStyle solid $a = 17 + 23; // A comment inside my example function
Outside of functions and methods, only the "
/
" and "/
" comment markers are allowed.Code Block borderStyle solid /* This method is required for compatibility issues */ public function foo() { // Some code explanation right here ... }
PHP Doc comment block is required before the declaration of the method.
Code Block borderStyle solid /** * 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 title For more informations For more informations information about the PHP Doc syntax: http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.pkg.html
...
The
return
statement does not need brackets, except when it deals with a composed expression.Code Block borderStyle solid return $result; return ($a + $b); return (a() - b()); return true;
The
return
statement can be used to break out of a function.Code Block borderStyle solid 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.
...