1 | <?php |
||
13 | class Handler implements ExceptionHandlerContract |
||
14 | { |
||
15 | protected $parentHandler; |
||
16 | |||
17 | public function __construct(ExceptionHandlerContract $parentHandler) |
||
21 | |||
22 | /** |
||
23 | * Report or log an exception. |
||
24 | * |
||
25 | * @param \Exception $exception |
||
26 | * |
||
27 | * @return void |
||
28 | * @throws \Exception |
||
29 | */ |
||
30 | public function report(Exception $exception) |
||
34 | |||
35 | /** |
||
36 | * Render an exception into a response. |
||
37 | * |
||
38 | * @param \Illuminate\Http\Request $request |
||
39 | * @param \Exception $exception |
||
40 | * |
||
41 | * @return \Symfony\Component\HttpFoundation\Response |
||
42 | */ |
||
43 | public function render($request, Exception $exception) |
||
59 | |||
60 | /** |
||
61 | * Render an exception to the console. |
||
62 | * |
||
63 | * @param \Symfony\Component\Console\Output\OutputInterface $output |
||
64 | * @param \Exception $exception |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | public function renderForConsole($output, Exception $exception) |
||
72 | |||
73 | /** |
||
74 | * Prepare exception for rendering. |
||
75 | * |
||
76 | * @param \Exception $exception |
||
77 | * @return \Exception |
||
78 | */ |
||
79 | protected function prepareException(Exception $exception) |
||
89 | |||
90 | /** |
||
91 | * Convert an authentication exception into an unauthenticated response. |
||
92 | * |
||
93 | * @param \Illuminate\Http\Request $request |
||
94 | * @param \Illuminate\Auth\AuthenticationException $exception |
||
95 | * @return \Illuminate\Http\Response |
||
96 | */ |
||
97 | protected function unauthenticated($request, AuthenticationException $exception) |
||
107 | |||
108 | /** |
||
109 | * Render the given HttpException. |
||
110 | * |
||
111 | * @param \Illuminate\Http\Request $request |
||
112 | * @param \Symfony\Component\HttpKernel\Exception\HttpException $exception |
||
113 | * @return \Symfony\Component\HttpFoundation\Response |
||
114 | */ |
||
115 | protected function renderHttpException($request, HttpException $exception) |
||
125 | |||
126 | protected function isAdmin($request) |
||
130 | } |
||
131 |
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: