31,026
edits
m (→Normes SQL) |
m (→PHP Norms) |
||
| Line 12: | Line 12: | ||
= PHP Norms = | = PHP Norms = | ||
{{ToTranslate}} | {{ToTranslate}} | ||
* Dolibarr | * Dolibarr is written with PHP and supports all PHP version higher than 4.1. All files must end with extension .php | ||
* | * Usage of superglobals PHP variables must use dedicated operators $_GET, $_POST, $_COOKIES, $_SERVER, $_ENV. | ||
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). | |||
* | * Smart tags PHP are not used. PHP code section must start with '''<?php''' | ||
* | * Do not use '''PHP_SELF'''. Use instead $_SERVER["PHP_SELF"]. | ||
* | * When several variables must be initialized with same value, you must use several lines | ||
<source lang="php"> | <source lang="php"> | ||
$var1=1;$var2=1;$var3=1; | $var1=1;$var2=1;$var3=1; | ||
</source> | </source> | ||
instead of | |||
<source lang="php"> | <source lang="php"> | ||
$var1=$var2=$var3=1; | $var1=$var2=$var3=1; | ||
</source> | </source> | ||
that is slower. | |||
* | * String must be rounded by simple quote and vairable inside string must be out of the quote. | ||
<source lang="php"> | <source lang="php"> | ||
print ' | print 'My text show my '.$variable.' !'; | ||
</source> | </source> | ||
* | * Comments must use the C syntax, ie a double antislash for a comment on one line and a slash-star to open a bloc for several lines | ||
<source lang="php"> | <source lang="php"> | ||
/* Bloc | /* Bloc of comment | ||
* | * | ||
* | * End of bloc | ||
*/ | */ | ||
| Line 49: | Line 49: | ||
for ($i = 1 , $i < 2 ; $i++) | for ($i = 1 , $i < 2 ; $i++) | ||
{ | { | ||
// | // comment on one line | ||
print $i; | print $i; | ||
} | } | ||
| Line 55: | Line 55: | ||
</source> | </source> | ||
* | * 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. | ||
Functions must return a value strictly higher than 0 if successfull and strictly lower than 0 if error. | |||
= SQL rules = | = SQL rules = | ||