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

[HttpFoundation] deprecate call to Request::getSession() when Request::hasSession() returns false #26564

Merged
merged 1 commit into from Mar 18, 2018

Conversation

Projects
None yet
5 participants
@fmata
Contributor

fmata commented Mar 16, 2018

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #26539
License MIT

@nicolas-grekas nicolas-grekas changed the title from [HttpFoundation] deprecate call to Request::getSession() when Request… to [HttpFoundation] deprecate call to Request::getSession() when Request::hasSession() returns false Mar 16, 2018

@@ -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);

This comment has been minimized.

@nicolas-grekas

nicolas-grekas Mar 16, 2018

Member

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 ...

This comment has been minimized.

@fmata

fmata Mar 16, 2018

Contributor

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 ?

This comment has been minimized.

@nicolas-grekas

nicolas-grekas Mar 16, 2018

Member

I think we can provide a friendlier message, don't you?

This comment has been minimized.

@fmata

fmata Mar 16, 2018

Contributor

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);

This comment has been minimized.

@Tobion

Tobion Mar 16, 2018

Member

typo: no session

This comment has been minimized.

@fmata

fmata Mar 17, 2018

Contributor

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.

This comment has been minimized.

@Tobion

Tobion Mar 17, 2018

Member

mentioning the deprecation in UPGRADE-4.1.md and HttpFoundation/CHANGELOG.md is missing

This comment has been minimized.

@fmata

fmata Mar 17, 2018

Contributor

Done. I will send a PR (edit : #26580) to update the Github PR template to help contributors to do such things, thanks.

@fabpot

fabpot approved these changes Mar 18, 2018

@fabpot

This comment has been minimized.

Member

fabpot commented Mar 18, 2018

Thank you @fmata.

@fabpot fabpot merged commit 4110d57 into symfony:master Mar 18, 2018

2 of 3 checks passed

continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

fabpot added a commit that referenced this pull request Mar 18, 2018

feature #26564 [HttpFoundation] deprecate call to Request::getSession…
…() 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

@fabpot fabpot referenced this pull request May 7, 2018

Merged

Release v4.1.0-BETA1 #27181

nicolas-grekas added a commit that referenced this pull request May 25, 2018

bug #27350 [HttpKernel] fix deprecation in AbstractTestSessionListene…
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment