-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] deprecate call to Request::getSession() when Request::hasSession() returns false #26564
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
Conversation
fmata
commented
Mar 16, 2018
•
edited by nicolas-grekas
Loading
edited by nicolas-grekas
Q | A |
---|---|
Branch? | master |
Bug fix? | no |
New feature? | no |
BC breaks? | no |
Deprecations? | yes |
Tests pass? | yes |
Fixed tickets | #26539 |
License | MIT |
@@ -725,6 +725,10 @@ public function getSession() | |||
$this->setSession($session = $session()); | |||
} | |||
|
|||
if (null === $session) { | |||
@trigger_error(sprintf('Calling "%s()" when "%s::hasSession()" returns false is deprecated since Symfony 4.1 and will throw an exception in 5.0.', __METHOD__, __CLASS__), E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling "%s()" when non session has been set is deprecated since Symfony 4.1 and will throw an exception in 5.0. Use "hasSession()" instead.
also, please add the exception tight now, but as a commented line, so that upgrading for 5.0 is made trivial:
// throw new ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message updated.
About the // throw new ...
I thought a type hinting on the return type with SessionInterface
was enough, PHP will throw :
TypeError : Return value of Request::getSession() must implement interface SessionInterface.
WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can provide a friendlier message, don't you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@@ -725,6 +725,11 @@ public function getSession() | |||
$this->setSession($session = $session()); | |||
} | |||
|
|||
if (null === $session) { | |||
@trigger_error(sprintf('Calling "%s()" when non 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: no session
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -54,6 +54,7 @@ HttpFoundation | |||
|
|||
* The `$size` argument of the `UploadedFile` constructor has been removed. | |||
* The `getClientSize()` method of the `UploadedFile` class has been removed. | |||
* The `getSession()` method of the `Request` class throws an exception when session is null. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mentioning the deprecation in UPGRADE-4.1.md and HttpFoundation/CHANGELOG.md is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I will send a PR (edit : #26580) to update the Github PR template to help contributors to do such things, thanks.
…::hasSession() returns false
Thank you @fmata. |
…() when Request::hasSession() returns false (fmata) This PR was merged into the 4.1-dev branch. Discussion ---------- [HttpFoundation] deprecate call to Request::getSession() when Request::hasSession() returns false | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #26539 | License | MIT Commits ------- 4110d57 [HttpFoundation] deprecate call to Request::getSession() when Request::hasSession() returns false
…r (alekitto) This PR was merged into the 4.1 branch. Discussion ---------- [HttpKernel] fix deprecation in AbstractTestSessionListener | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT After #26564 functional tests began to emit a deprecation warning because of `getSession()` being called without verifying the existence of a session. Commits ------- 0ecaefe [HttpKernel] fix deprecation in AbstractTestSessionListener