1 | <?php |
||
12 | class EquitableScoreControl |
||
13 | { |
||
14 | private $escResultArray; |
||
15 | |||
16 | /** |
||
17 | * |
||
18 | * @param array $holeScores |
||
19 | * @param $courseHandicap |
||
20 | * @return array |
||
21 | */ |
||
22 | 1 | public function adjustScores(array $holeScores, $courseHandicap) |
|
36 | |||
37 | // Using a players course handicap which is a whole number |
||
38 | /** |
||
39 | * @param $par |
||
40 | * @param $courseHandicap |
||
41 | * @return int |
||
42 | */ |
||
43 | 2 | public function getMaxAllowableHoleScore($par, $courseHandicap) |
|
63 | } |
||
64 |
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: