1 | <?php |
||
18 | class Retrieve |
||
19 | { |
||
20 | /** |
||
21 | * SAT Endpoint |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | const SAT_ENDPOINT = 'http://www.sat.gob.mx/sitio_internet/cfd/3/cadenaoriginal_3_3/cadenaoriginal_3_3.xslt'; |
||
26 | |||
27 | /** |
||
28 | * @return array |
||
29 | */ |
||
30 | protected function getIncludeFiles(): array |
||
44 | |||
45 | /** |
||
46 | * @param string $directory |
||
47 | * |
||
48 | * @return bool |
||
49 | */ |
||
50 | public function changeNodeReference(string $directory): bool |
||
71 | |||
72 | /** |
||
73 | * @param string $directory |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | public function download(string $directory): bool |
||
90 | |||
91 | /** |
||
92 | * @param string $file |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | protected function getFileName(string $file): string |
||
100 | } |
||
101 |
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.