Conditions | 2 |
Paths | 4 |
Total Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
11 | public function process(HTTPRequest $request, callable $delegate) |
||
12 | { |
||
13 | try { |
||
14 | // Start session and execute |
||
15 | $request->getSession()->init($request); |
||
16 | |||
17 | // Generate output |
||
18 | $response = $delegate($request); |
||
19 | } finally { |
||
20 | // Save session data, even if there was an exception |
||
21 | // Note that save() will start/resume the session if required. |
||
22 | $request->getSession()->save($request); |
||
23 | |||
24 | if (HybridSession::is_enabled()) { |
||
25 | // Close the session |
||
26 | session_write_close(); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | return $response; |
||
|
|||
31 | } |
||
32 | } |
||
33 |
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: