1 | <?php |
||
24 | class IdentitySearchQuery implements HttpQuery |
||
25 | { |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $nameId; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $institution; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private $email; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $commonName; |
||
45 | |||
46 | /** |
||
47 | * @param string $institution |
||
48 | * @return IdentitySearchQuery |
||
49 | */ |
||
50 | public function setInstitution($institution) |
||
58 | |||
59 | /** |
||
60 | * @param string $commonName |
||
61 | * @return IdentitySearchQuery |
||
62 | */ |
||
63 | public function setCommonName($commonName) |
||
71 | |||
72 | /** |
||
73 | * @param string $email |
||
74 | * @return IdentitySearchQuery |
||
75 | */ |
||
76 | public function setEmail($email) |
||
84 | |||
85 | /** |
||
86 | * @param string $nameId |
||
87 | * @return IdentitySearchQuery |
||
88 | */ |
||
89 | public function setNameId($nameId) |
||
97 | |||
98 | private function assertNonEmptyString($value, $name) |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | public function toHttpQuery() |
||
132 | } |
||
133 |
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: