1 | <?php |
||
7 | class DataTransformer |
||
8 | { |
||
9 | /** |
||
10 | * @param array $samples |
||
11 | * @param array $labels |
||
12 | * @param bool $targets |
||
13 | * |
||
14 | * @return string |
||
15 | */ |
||
16 | public static function trainingSet(array $samples, array $labels, bool $targets = false): string |
||
29 | |||
30 | /** |
||
31 | * @param array $samples |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | public static function testSet(array $samples): string |
||
48 | |||
49 | /** |
||
50 | * @param string $rawPredictions |
||
51 | * @param array $labels |
||
52 | * |
||
53 | * @return array |
||
54 | */ |
||
55 | public static function predictions(string $rawPredictions, array $labels): array |
||
67 | |||
68 | /** |
||
69 | * @param array $labels |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | public static function numericLabels(array $labels): array |
||
86 | |||
87 | /** |
||
88 | * @param array $sample |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | private static function sampleRow(array $sample): string |
||
101 | } |
||
102 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: