Skip to content

Commit 5ec123f

Browse files
committed
bug symfony#15243 Reload the session after regenerating its id (jakzal)
This PR was merged into the 2.3 branch. Discussion ---------- Reload the session after regenerating its id | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#15033 | License | MIT | Doc PR | - This is a fix preventing [a PHP bug](https://bugs.php.net/bug.php?id=70013), which I'm not sure when or IF is going to be fixed. Commits ------- 99b9c78 [HttpFoundation] Reload the session after regenerating its id eda5cb1 [HttpFoundation] Add a test case to confirm a bug in session migration
2 parents 6f8a37c + 99b9c78 commit 5ec123f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,13 @@ public function regenerate($destroy = false, $lifetime = null)
203203
$this->metadataBag->stampNew();
204204
}
205205

206-
return session_regenerate_id($destroy);
206+
$isRegenerated = session_regenerate_id($destroy);
207+
208+
// The reference to $_SESSION in session bags is lost in PHP7 and we need to re-create it.
209+
// @see https://bugs.php.net/bug.php?id=70013
210+
$this->loadSession();
211+
212+
return $isRegenerated;
207213
}
208214

209215
/**

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ public function testRegenerateDestroy()
119119
$this->assertEquals(11, $storage->getBag('attributes')->get('legs'));
120120
}
121121

122+
public function testSessionGlobalIsUpToDateAfterIdRegeneration()
123+
{
124+
$storage = $this->getStorage();
125+
$storage->start();
126+
$storage->getBag('attributes')->set('lucky', 7);
127+
$storage->regenerate();
128+
$storage->getBag('attributes')->set('lucky', 42);
129+
130+
$this->assertEquals(42, $_SESSION['_sf2_attributes']['lucky']);
131+
}
132+
122133
public function testDefaultSessionCacheLimiter()
123134
{
124135
$this->iniSet('session.cache_limiter', 'nocache');

0 commit comments

Comments
 (0)