1 | <?php |
||
10 | final class DiscoveryPass implements CompilerPassInterface |
||
11 | { |
||
12 | /** |
||
13 | * Fallback services and classes. |
||
14 | * |
||
15 | * @var array |
||
16 | */ |
||
17 | private $services = [ |
||
18 | 'client' => 'Http\Client\HttpClient', |
||
19 | 'message_factory' => 'Http\Message\MessageFactory', |
||
20 | 'uri_factory' => 'Http\Message\UriFactory', |
||
21 | 'stream_factory' => 'Http\Message\StreamFactory', |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | public function process(ContainerBuilder $container) |
||
54 | |||
55 | /** |
||
56 | * @param ContainerBuilder $container |
||
57 | * |
||
58 | * @throws RuntimeException |
||
59 | */ |
||
60 | private function registerFactory(ContainerBuilder $container) |
||
75 | } |
||
76 |
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: