Skip to content

[HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2 #24531

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
Nov 5, 2017

Conversation

sroze
Copy link
Contributor

@sroze sroze commented Oct 12, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #24524
License MIT
Doc PR ø

PHP 7.2 disallow setting session options when the session was already started. This PR will not set any option if the session is already started and throw an exception if trying to do so with custom options.

@sroze sroze force-pushed the native-storage-and-php72 branch 2 times, most recently from 35d4024 to 426a0cb Compare October 12, 2017 10:53
sroze added a commit to sroze/symfony that referenced this pull request Oct 12, 2017
$this->getStorage();

// Assert no exception has been thrown by `getStorage()`
$this->assertTrue(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

$this->addToAssertionCount(1);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the difference?

Copy link
Member

Choose a reason for hiding this comment

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

semantic: more explicit

*/
public function testCannotSetSessionOptionsOnceSessionStarted()
{
if (PHP_VERSION_ID < 70200) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Annotation @requires PHP 7.2.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would that allow 7.2 and above or lock at 7.2.* or 7.(2+) ?

Copy link
Member

Choose a reason for hiding this comment

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

@requires PHP 7.2 works

Copy link
Contributor

@Simperfit Simperfit left a comment

Choose a reason for hiding this comment

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

Please look at the appveyor build the constant seems undefined

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Oct 12, 2017
session_register_shutdown();
$this->setMetadataBag($metaBag);

if (PHP_VERSION_ID >= 70200 && \PHP_SESSION_ACTIVE === session_status()) {
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 should try as much as possible to NOT have a different behavior on 7.2 than before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be a BC break if we don't add this version condition as it's a behaviour changed in PHP's runtime.

Copy link
Member

Choose a reason for hiding this comment

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

upgrading to 7.2 will hit the BC break, so this doesn't prevent it, it just hides it :)

Copy link
Contributor Author

@sroze sroze Oct 12, 2017

Choose a reason for hiding this comment

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

Fair enough. So you'd like me to remove the PHP version condition in here? Note that we'll have to add a check to know if the constant exists for old Windows builds as apparently it doesn't exists. (dunno what's the limit but OK for master but not 2.7 on AppVeyor)

Copy link
Member

Choose a reason for hiding this comment

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

should be a no-op then, which matches the behavior pre-7.2
on 3.4, we could trigger a deprecation, and throw on 4.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, let's do this in three PRs instead of directly throwing on 2.7:

  1. On 2.7, just ignore and don't set the options/handler so it won't break with the INI settings issue
  2. On 3.4, trigger a deprecation
  3. On master, throw an exception

@nicolas-grekas
Copy link
Member

Status: needs work

@sroze
Copy link
Contributor Author

sroze commented Oct 14, 2017

PR changed to be the first one of three. This one, on 2.7, simply ignores the extra options if the session is already started.

Once merged, I'll issue two other ones:

  1. Instead of ignoring, we will send a deprecation on 3.4
  2. Instead of the deprecation, we will throw an exception on 4.0

@sroze
Copy link
Contributor Author

sroze commented Oct 14, 2017

Status: Needs review

ping @nicolas-grekas

@sroze
Copy link
Contributor Author

sroze commented Oct 14, 2017

And when merged we should finally be able to get green tests with PHP 7.2 in #24516.

@sroze
Copy link
Contributor Author

sroze commented Oct 23, 2017

👋 @symfony/mergers should we go ahead with this first PR for PHP 7.2 support (i.e. green tests) ?

@nicolas-grekas nicolas-grekas self-requested a review October 28, 2017 16:35
@@ -102,6 +102,12 @@ class NativeSessionStorage implements SessionStorageInterface
*/
public function __construct(array $options = array(), $handler = null, MetadataBag $metaBag = null)
{
$this->setMetadataBag($metaBag);

if (PHP_VERSION_ID >= 70200 && \PHP_SESSION_ACTIVE === session_status()) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to remove the PHP_VERSION_ID >= 70200 part: the behavior should be consistent across versions.

}

/**
* @requires PHP 7.2
Copy link
Member

Choose a reason for hiding this comment

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

see previous comment, might be removed

@nicolas-grekas nicolas-grekas force-pushed the native-storage-and-php72 branch from a930a67 to e54c292 Compare November 5, 2017 18:30
@nicolas-grekas nicolas-grekas changed the title [HttpFundation] Create the native session storage with PHP 7.2 [HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2 Nov 5, 2017
@nicolas-grekas nicolas-grekas force-pushed the native-storage-and-php72 branch 2 times, most recently from 23d917f to 34faff7 Compare November 5, 2017 18:33
@nicolas-grekas nicolas-grekas force-pushed the native-storage-and-php72 branch from 34faff7 to 00a1357 Compare November 5, 2017 18:48
@nicolas-grekas
Copy link
Member

Thank you @sroze.

@nicolas-grekas nicolas-grekas merged commit 00a1357 into symfony:2.7 Nov 5, 2017
nicolas-grekas added a commit that referenced this pull request Nov 5, 2017
…e with PHP 7.2 (sroze)

This PR was merged into the 2.7 branch.

Discussion
----------

[HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24524
| License       | MIT
| Doc PR        | ø

PHP 7.2 disallow setting session options when the session was already started. This PR will not set any option if the session is already started and throw an exception if trying to do so with custom options.

Commits
-------

00a1357 [HttpFoundation] Fix forward-compat of NativeSessionStorage with PHP 7.2
This was referenced Nov 5, 2017
@sroze sroze deleted the native-storage-and-php72 branch November 6, 2017 08:16
@sroze
Copy link
Contributor Author

sroze commented Nov 6, 2017

@nicolas-grekas thanks for updating. Based on your changes... do you still think that we should deprecate and throw when options are tried to be changed?

@nicolas-grekas
Copy link
Member

@sroze not high priority, but we should try for 4.1 or up

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.

6 participants