1 | <?php |
||
5 | final class Locale |
||
6 | { |
||
7 | /** |
||
8 | * @var string Locale key identifier |
||
9 | */ |
||
10 | private $value; |
||
11 | |||
12 | 82 | private function __construct(string $value) |
|
16 | |||
17 | 82 | public static function from(string $value) |
|
21 | |||
22 | 2 | public function withoutRegion() |
|
32 | |||
33 | 69 | public function get(): string |
|
37 | |||
38 | 1 | public function equals(self $other): bool |
|
42 | |||
43 | 69 | public function __toString(): string |
|
47 | } |
||
48 |
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: