Language and development rules: Difference between revisions

Jump to navigation Jump to search
m
Line 23: Line 23:
= PHP Norms =
= PHP Norms =
== PHP ==
== PHP ==
* Dolibarr is written with PHP and supports all PHP version higher than {{PHPMinVersion}}. All files must end with extension .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 content of $_GET or $_POST..
* 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 inside PHP, so they must no more be used. Like that code will work also if option '''register_long_arrays''' is set to off.
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 same way when the option '''register_globals''' is on (by default on a lot of installations).
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, so before any business code).
* 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 several instructions (separated with ;)
* 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>
that is slower.
which is slower.


* String must be rounded by simple or double quote and a variable within the string must be out side of the quote.
* 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.' !';
98

edits

Navigation menu