Ok, i'm very confused. I'm using the Slim framework and I have following Code:
1 $app->post("/user/login", function (Request $request, Response $response) {
2 $resp = null;
3 try {
4 if (!array_key_exists("password", $request->getParams()) || !array_key_exists("username", $request->getParams())) {
5 throw new LiberInvalidRequestException("Not all required parameters were passed.");
6 }
7 $user = new User($this->db, [
8 'username' => $request->getParam('username'),
9 'password' => $request->getParam('password')
10 ]);
11 try {
12 $resp['logincode'] = $user->login();
13 $resp['success'] = true;
14 } catch (LiberAuthenticationException $exception) {
15 $resp['success'] = false;
16 $resp['errormessage'] = $exception->getMessage();
17 }
18 } catch (LiberInvalidRequestException $exception) {
19 $resp['success'] = false;
20 $resp['errormessage'] = $exception->getMessage();
21 } finally {
22 return $response->withJson($resp);
23 }
24 });
When I call this route with the right params i get a null
response. In my opinion this shouldn't be possible because in every possible way something is assigned to $resp
. When i go through this function with the debugger I can go until line 12 then the debugger jumps to the finally block (line 22).
How is this even possible? Shouldn't the execution continue or go to the catch block?