1 | <?php |
||
7 | class Points { |
||
8 | //-------------------------- BUILDER ----------------------------------------------------------------------------// |
||
9 | public function __construct($start = null) { |
||
41 | //-------------------------- END BUILDER ----------------------------------------------------------------------------// |
||
42 | |||
43 | |||
44 | //-------------------------- GETTER ----------------------------------------------------------------------------// |
||
45 | /** |
||
46 | * @param $id_base |
||
47 | * @return int |
||
48 | * renvoi les points de la base |
||
49 | */ |
||
50 | public static function getPointsBase($id_base) { |
||
68 | |||
69 | /** |
||
70 | * @return mixed |
||
71 | * fonction qui renvoi le nombre de points à ajouter à la base lorsqu'on update un batiment |
||
72 | */ |
||
73 | private static function getPointAjoutBatiment() { |
||
76 | //-------------------------- END GETTER ----------------------------------------------------------------------------// |
||
77 | |||
78 | |||
79 | //-------------------------- SETTER ----------------------------------------------------------------------------// |
||
80 | /** |
||
81 | * @param $id_base |
||
82 | * @param null $type |
||
83 | * @param null $points |
||
84 | * @return int|null |
||
85 | * fonction qui ajoute des points à la base en fonction du type |
||
86 | * le type peut etre : batiment, attaque, defense, troupe |
||
87 | */ |
||
88 | public static function setAjouterPoints($id_base, $type=null, $points=null) { |
||
105 | //-------------------------- END SETTER ----------------------------------------------------------------------------// |
||
106 | |||
107 | } |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.