CodingStandards » History » Version 15

« Previous - Version 15/64 (diff) - Next » - Current version
moyo, 08/19/2006 03:32 AM


Indentation

One tabulation

{{{
// base level
// level 1
// level 2
// level 1
// base level
?>
}}}

Control structures

Multiple conditions in several idented lines

{{{
if ($test1){
for ($i=0;$i<$end;$i++){
echo "test ".( $i<10 ? "0$i" : $i )."<br>";
}
}

if ($a==$b | ($c==$d
&& $e==$f)){

}

switch ($test2){
case 1 :
echo "Case 1";
break;
case 2 :
echo "Case 2";
break;
default :
echo "Default Case";
break;
}

?>
}}}

Including files

require_once in order to include the file once and to raise error if file does not exists

{{{
require_once("_relpos.php");
}}}

PHP tags

Short tag not allowed. Use complet tags.

{{{

// code

?>
}}}

Functions

Function names should be written in camelBack, for example:

{{{
function userName() {
}
?>
}}}

Class

Class names should be written in CamelCase, for example:

{{{
class ExampleAuthentification {
}
?>
}}}

Variables

Variable names should be as descriptive and short as possible.
Normal variables should be written in lower case. In case of multiple words use the _ separator.
Global variables should be written in UPPER case. In case of multiple words use the _ separator.

Example:

{{{
$user = 'glpi';
$users = array('glpi', 'glpi2', 'glpi3');
$users_groups = array('glpi', 'glpi2', 'glpi3');

$CFG_GLPI=array();

?>

}}}

Variable types

Variable types for use in DocBlocks for Doxygen:

Type Description
mixed A variable with undefined (or multiple) type.
integer Integer type variable (whole number).
float Float type (point number).
boolean Logical type (true or false).
string String type (any value in "" or ' ').
array Array type.
object Object type.
ressource Resource type (returned by for example mysql_connect()).
Files

Name in lower case.
Maximum line length : 100 characters

Constants

Capital letter :

{{{
COMPUTER_TYPE
}}}

MySQL

Request must be writtent on several lines, a MySQL item by line.
All MySQL words in UPPER case.

{{{
SELECT *
FROM `glpi_computers`
WHERE ID='32'
AND ( name LIKE '%toto%'
OR name LIKE '%tata%' )
ORDER BY date_mod ASC
LIMIT 1
}}}