Skip to content

[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

Merged
merged 1 commit into from
Mar 18, 2018

Conversation

fmata
Copy link
Contributor

@fmata 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 [HttpFoundation] deprecate call to Request::getSession() when Request… [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);
Copy link
Member

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

Copy link
Contributor Author

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 ?

Copy link
Member

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?

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: no session

Copy link
Contributor Author

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.
Copy link
Contributor

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

Copy link
Contributor Author

@fmata fmata Mar 17, 2018

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.

@fabpot
Copy link
Member

fabpot commented Mar 18, 2018

Thank you @fmata.

@fabpot fabpot merged commit 4110d57 into symfony:master Mar 18, 2018
fabpot added a commit that referenced this pull request Mar 18, 2018
…() 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 mentioned this pull request May 7, 2018
nicolas-grekas added a commit that referenced this pull request May 25, 2018
…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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants