Language and development rules: Difference between revisions

Jump to navigation Jump to search
m
Line 12: Line 12:
= PHP Norms =
= PHP Norms =
{{ToTranslate}}
{{ToTranslate}}
* Dolibarr est écrit en PHP et supporte toutes versions PHP supérieures à la 4.1. Les fichiers doivent tous comporter l'extension .php
* Dolibarr is written with PHP and supports all PHP version higher than 4.1. All files must end with extension .php


* L'appel aux variables superglobales PHP doit passer par les opérateurs dédiés $_GET, $_POST, $_COOKIES, $_SERVER, $_ENV.
* Usage of superglobals PHP variables must use dedicated operators $_GET, $_POST, $_COOKIES, $_SERVER, $_ENV.
Les autres opérateurs ($HTTP_SERVER_GET, ...) ayant été passés en deprecated au sein de PHP, ne doivent plus être utilisés. Ainsi le code doit fonctionner y compris quand l'option '''register_long_arrays''' est à 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.
De plus, le code doit fonctionner quand l'option PHP '''register_globals''' est à off (recommandé par PHP) aussi bien que quand l'option '''register_globals''' à on (par défaut sur de nombreuses 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).


* Les smart tags PHP ne sont pas utilisés. Les sections de code doivent commencer par '''<?php'''
* Smart tags PHP are not used. PHP code section must start with '''<?php'''


* Pas d'utilisation de la variable '''PHP_SELF'''. Utiliser a la place $_SERVER["PHP_SELF"]
* Do not use '''PHP_SELF'''. Use instead $_SERVER["PHP_SELF"].


* Quand plusieurs variables doivent être initialisées avec la même valeur, il faut utiliser plusieurs lignes
* 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>
plutôt que
instead of
<source lang="php">
<source lang="php">
$var1=$var2=$var3=1;
$var1=$var2=$var3=1;
</source>
</source>
qui est moins performant.
that is slower.


* Les chaines doivent être encadrés de simple quote et les variables sorties de la chaine.
* String must be rounded by simple quote and vairable inside string must be out of the quote.
<source lang="php">
<source lang="php">
print 'Mon texte affiche ma '.$variable.' !';
print 'My text show my '.$variable.' !';
</source>
</source>


* Les commentaires doivent suivre la syntaxe C, ie un double antislash pour un commentaire d'une ligne et utilisation slash-étoile pour ouvrir un bloc de plusieurs lignes
* 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 de commentaire
/* Bloc of comment
  *
  *
  * Fin du bloc
  * End of bloc
  */
  */


Line 49: Line 49:
for ($i = 1 , $i < 2 ; $i++)
for ($i = 1 , $i < 2 ; $i++)
{
{
   // commentaire sur une ligne
   // comment on one line
   print $i;
   print $i;
}
}
Line 55: Line 55:
</source>
</source>


* Les fichiers doivent etre sauvés en format Unix (LF) et non Windows (CR/LF). Le format Unix étant compatible sur les OS Unix like, Windows, Mac, alors que le format fichier texte Windows pose problème sous certains PHP sous Unix.
* 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.


Les fonctions doivent retourner 0 en cas de succès, et un nombre <0 en cas d'erreur.
Functions must return a value strictly higher than 0 if successfull and strictly lower than 0 if error.
A ce jour, très peu de fonctions respectent ce standard mais c'est celui vers lequel il faut tendre.


= SQL rules =
= SQL rules =

Navigation menu