31,014
edits
| Line 27: | Line 27: | ||
Other operators ($HTTP_SERVER_GET, ...) are now deprecated inside PHP, so they must no more be used. Like that code will works alos if option '''register_long_arrays''' is to off. | Other operators ($HTTP_SERVER_GET, ...) are now deprecated inside PHP, so they must no more be used. Like that code will works alos if option '''register_long_arrays''' is to off. | ||
Moreover, the code must works when PHP option '''register_globals''' is off (recommanded by PHP). It must works the same way that when option '''register_globals''' is on (by default on a lot of installations). | Moreover, the code must works when PHP option '''register_globals''' is off (recommanded by PHP). It must works the same way that when option '''register_globals''' is on (by default on a lot of installations). | ||
* Do not use '''PHP_SELF'''. Use instead $_SERVER["PHP_SELF"]. | * Do not use '''PHP_SELF'''. Use instead $_SERVER["PHP_SELF"]. | ||
| Line 42: | Line 40: | ||
that is slower. | that is slower. | ||
* String must be rounded by simple quote and | * String must be rounded by simple quote and variable inside string must be out of the quote. | ||
<source lang="php"> | <source lang="php"> | ||
print 'My text show my '.$variable.' !'; | print 'My text show my '.$variable.' !'; | ||
| Line 64: | Line 62: | ||
</source> | </source> | ||
* Functions must return a value strictly higher than 0 if successfull and strictly lower than 0 if error. | * Functions must return a value strictly higher than 0 if successfull and strictly lower than 0 if error. | ||
| Line 72: | Line 68: | ||
* Use "include_once" for anything with functions or class definitions in it (so *.class.php and *.lib.php files), use "include" for template-style php with files containing a mix of HTML and PHP (so *.inc.php and *.tpl.php files). | * Use "include_once" for anything with functions or class definitions in it (so *.class.php and *.lib.php files), use "include" for template-style php with files containing a mix of HTML and PHP (so *.inc.php and *.tpl.php files). | ||
* Coding style to use is the PSR-2 (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) with 2 exceptions, this means: | |||
** Files must be saved with Unix format (LF) and not Windows (CR/LF). Unif format is compatible on all OS like Unix like, Windows, Mac, but the Windows text file format is no working on some PHP under Unix. | |||
** Smart tags PHP are not used. PHP code section must start with '''<?php''' | |||
** But there is an exception of length of line: We accept 1000 characters on same line if chars are not | |||
** The other exception is that we don't replace the tab with space. This make lot of editor crazy and break some autoformat features broken. | |||
You can use the file dev/codesniffer/ruleset.xml as rule file to control coding style with PHPCodeSniffer. | |||
= SQL rules = | = SQL rules = | ||