1 | <?php |
||
12 | trait ArrayTrait |
||
13 | { |
||
14 | /** |
||
15 | * Performs an operation in a given array. |
||
16 | * It stops if 'strict' is set to true and the result of the operation is false. |
||
17 | * |
||
18 | * @param array $values The array |
||
19 | * @param mixed $args The arguments to pass to the operation |
||
20 | * @param callable $do The operation |
||
21 | * |
||
22 | * @return bool |
||
23 | */ |
||
24 | public function inArray($values, $args, $do, $strict = false) |
||
39 | |||
40 | /** |
||
41 | * Eliminate nested array when passing parameters. |
||
42 | * |
||
43 | * @param array $value The array to eliminate layer up |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | protected function toArray($value) |
||
55 | } |
||
56 |
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: