1 | <?php |
||
8 | abstract class AbstractMetricsLoader extends AbstractLoader |
||
9 | { |
||
10 | /** |
||
11 | * Allows injection of where statements |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $metrics = []; |
||
16 | |||
17 | /** |
||
18 | * Returns metrics for a particular result |
||
19 | * |
||
20 | * @param string $id |
||
21 | * |
||
22 | * @return array |
||
23 | */ |
||
24 | public function readSingle($id) |
||
60 | |||
61 | /** |
||
62 | * Allows setting of metrics to filter |
||
63 | * |
||
64 | * @param array |
||
65 | */ |
||
66 | public function setMetrics($metric) |
||
76 | |||
77 | /** |
||
78 | * Pulls in metrics |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | public function getMetrics() |
||
86 | } |
||
87 |
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
The above code is perfectly fine. Now imagine that we re-order the statements:
In that case,
$x
would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.