-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Description
Since #38616 there's exception type variance in getSession()
between RequestStack
and Request
, when the session is not found
symfony/src/Symfony/Component/HttpFoundation/RequestStack.php
Lines 110 to 112 in a12db94
* @throws SessionNotFoundException | |
*/ | |
public function getSession(): SessionInterface |
vs.
symfony/src/Symfony/Component/HttpFoundation/Request.php
Lines 737 to 738 in a12db94
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
symfony/src/Symfony/Component/HttpFoundation/Request.php
Lines 726 to 727 in f1a7dca
@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