98
edits
m (→PHP) |
m (→PHP Norms) |
||
| Line 23: | Line 23: | ||
= PHP Norms = | = PHP Norms = | ||
== PHP == | == PHP == | ||
* Dolibarr is written with PHP and supports all PHP | * Dolibarr is written with PHP and supports all versions of PHP higher than {{PHPMinVersion}}. All files must end with extension .php | ||
* Usage of PHP superglobals variables must use dedicated operators $_COOKIES, $_SERVER, $_ENV but use Dolibarr function GETPOST() to get | * Usage of PHP superglobals variables must use the dedicated operators $_COOKIES, $_SERVER, $_ENV but use the Dolibarr function GETPOST() to get the contents of $_GET or $_POST.. | ||
Other operators ($HTTP_SERVER_GET, ...) are now deprecated | Other operators ($HTTP_SERVER_GET, ...) are now deprecated in PHP, so they must not be used. Code must work if option '''register_long_arrays''' is set to off. | ||
Moreover, the code must work when PHP option '''register_globals''' is off (recommended by PHP). It must work the | Moreover, the code must work when PHP option '''register_globals''' is off (recommended by PHP). It must also work the if the option '''register_globals''' is on (by default on a lot of installations). | ||
* Do not use '''PHP_SELF'''. Use instead $_SERVER["PHP_SELF"]. Also, Dolibarr framework sanitizes content of $_SERVER["PHP_SELF"] variable (into main.inc.php file, | * Do not use '''PHP_SELF'''. Use instead $_SERVER["PHP_SELF"]. Also, Dolibarr framework sanitizes content of $_SERVER["PHP_SELF"] variable (into main.inc.php file, before any business code). | ||
* When several variables must be initialized with same value, you must use | * When several variables must be initialized with the same value, you must use individual declarations (separated by ;) | ||
<source lang="php"> | <source lang="php"> | ||
$var1=1;$var2=1;$var3=1; | $var1=1;$var2=1;$var3=1; | ||
| Line 39: | Line 39: | ||
$var1=$var2=$var3=1; | $var1=$var2=$var3=1; | ||
</source> | </source> | ||
which is slower. | |||
* | * Strings must be delimited by a single or double quote and a variable within the string must be outside of the quote. | ||
<source lang="php"> | <source lang="php"> | ||
print 'My text show my '.$variable.' !'; | print 'My text show my '.$variable.' !'; | ||
edits