1 | <?php |
||
9 | class Point implements ArrayAccess |
||
10 | { |
||
11 | /** |
||
12 | * @var int |
||
13 | */ |
||
14 | protected $dimension; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $coordinates; |
||
20 | |||
21 | /** |
||
22 | * @param array $coordinates |
||
23 | */ |
||
24 | public function __construct(array $coordinates) |
||
29 | |||
30 | /** |
||
31 | * @return array |
||
32 | */ |
||
33 | public function toArray() |
||
37 | |||
38 | /** |
||
39 | * @param Point $point |
||
40 | * @param bool $precise |
||
41 | * |
||
42 | * @return int|mixed |
||
43 | */ |
||
44 | public function getDistanceWith(self $point, $precise = true) |
||
54 | |||
55 | /** |
||
56 | * @param $points |
||
57 | * |
||
58 | * @return mixed |
||
59 | */ |
||
60 | public function getClosest($points) |
||
79 | |||
80 | /** |
||
81 | * @return array |
||
82 | */ |
||
83 | public function getCoordinates() |
||
87 | |||
88 | /** |
||
89 | * @param mixed $offset |
||
90 | * |
||
91 | * @return bool |
||
92 | */ |
||
93 | public function offsetExists($offset) |
||
97 | |||
98 | /** |
||
99 | * @param mixed $offset |
||
100 | * |
||
101 | * @return mixed |
||
102 | */ |
||
103 | public function offsetGet($offset) |
||
107 | |||
108 | /** |
||
109 | * @param mixed $offset |
||
110 | * @param mixed $value |
||
111 | */ |
||
112 | public function offsetSet($offset, $value) |
||
116 | |||
117 | /** |
||
118 | * @param mixed $offset |
||
119 | */ |
||
120 | public function offsetUnset($offset) |
||
124 | } |
||
125 |
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: