Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request::getSession and null return value. #56

Closed
pplotka opened this issue Jul 30, 2019 · 1 comment · Fixed by #58
Closed

Request::getSession and null return value. #56

pplotka opened this issue Jul 30, 2019 · 1 comment · Fixed by #58

Comments

@pplotka
Copy link
Contributor

pplotka commented Jul 30, 2019

Request's method getSession can return null value, so when I tried call code like this: $request->getSession()->set(...) I got error:

Cannot call method set() on Symfony\Component\HttpFoundation\Session\SessionInterface|null.

I thought that checking if a request has sessions before call setter, resolve the problem, but unfortunately not. I created a repo which gives You a possibility to reproduce the problem:

https://github.com/plotek/symfony-phpstan

Possible workaround:

if ($request->hasSession()) {
    $session = $request->getSession();
    Assert::isInstanceOf($session, SessionInterface::class);
    $session->set('Test', 'Value');
}
@github-actions
Copy link

github-actions bot commented May 1, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant