Skip to content

[HttpFoundation] Sync session not found exception #40112

Closed
@ro0NL

Description

@ro0NL

Since #38616 there's exception type variance in getSession() between RequestStack and Request, when the session is not found

* @throws SessionNotFoundException
*/
public function getSession(): SessionInterface

vs.

if (null === $session) {
throw new \BadMethodCallException('Session has not been set.');

for simplicity, i think we should throw the same exception type in Request::getSession(), and let RequestStack simply forward the call.

the catch(BadMethodCallException) as "cheap hasSession" will break, but we explicitly mentioned to use hasSession instead already

@trigger_error(sprintf('Calling "%s()" when no session has been set is deprecated since Symfony 4.1 and will throw an exception in 5.0. Use "hasSession()" instead.', __METHOD__), \E_USER_DEPRECATED);
// throw new \BadMethodCallException('Session has not been set.');

ppl doing it as of 5.x rely on implementation details (the @throws BadMethodCallException isnt documented)

so, given both are LogicException it seems reasonable :)

cc @jderusse

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions