1 | <?php |
||
14 | class Helper |
||
15 | { |
||
16 | /** |
||
17 | * Convert a string to camelCase. Strings already in camelCase will not be modified |
||
18 | * |
||
19 | * @param string $string The input string |
||
20 | * @return string The output string |
||
21 | */ |
||
22 | 18 | public static function camelCase($string) |
|
33 | |||
34 | /** |
||
35 | * Convert strings with underscores to all lowercase |
||
36 | * |
||
37 | * @param string string The input string |
||
38 | * @return string The output string |
||
39 | */ |
||
40 | 18 | protected static function convertToLowercase($string) |
|
53 | |||
54 | /** |
||
55 | * Initialize an object with the given parameters |
||
56 | * |
||
57 | * @param mixed $target The object to set parameters on |
||
58 | * @param array $parameters The parameters to set |
||
59 | */ |
||
60 | 42 | public static function initialize($target, $parameters) |
|
71 | } |
||
72 |
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.