1 | <?php |
||
18 | class PDOMySqlExtensionCheck implements CheckInterface |
||
19 | { |
||
20 | /** |
||
21 | * Version of PDO extension |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | private $pdoVersion = ''; |
||
26 | |||
27 | /** |
||
28 | * Version of pdo_mysql extension |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $pdoMySqlVersion = ''; |
||
33 | |||
34 | /** |
||
35 | * Executes the check itselfs |
||
36 | * |
||
37 | * @return boolean |
||
38 | */ |
||
39 | 1 | public function check() |
|
56 | |||
57 | /** |
||
58 | * Returns the message, if the check succeeded |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | 1 | public function getSuccessMessage() |
|
68 | |||
69 | /** |
||
70 | * Returns the message, if the check fails |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | 1 | public function getFailureMessage() |
|
86 | |||
87 | /** |
||
88 | * Returns if this check is optional or required. |
||
89 | * |
||
90 | * @return bool |
||
91 | */ |
||
92 | 1 | public function isOptional() |
|
96 | } |
||
97 |
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: