8000 bug #46808 [HttpFoundation] Fix TypeError on null `$_SESSION` in `Na… · symfony/symfony@2670125 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2670125

Browse files
bug #46808 [HttpFoundation] Fix TypeError on null $_SESSION in NativeSessionStorage::save() (chalasr)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Fix TypeError on null `$_SESSION` in `NativeSessionStorage::save()` | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - When sending concurrent requests via ajax async to a route pointing to a controller requiring an authenticated user through a stateful - session-based - firewall that calls `SessionInterface::save()`, it happens that `$_SESSION` is `null` under some conditions which causes the following error on PHP 8.1: > Exception 'TypeError' with message 'array_keys(): Argument #1 ($array) must be of type array, null given' in /app/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:246 …app/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php (246) …age::save called at /app/vendor/symfony/http-foundation/Session/Session.php (198) The issue prevents me from upgrading to PHP 8.1 in a project I'm working on with `@jwage`. Commits ------- 05f3e77 [HttpFoundation] Fix TypeError on null `$_SESSION` in `NativeSessionStorage::save()`
2 parents 04ae33a + 05f3e77 commit 2670125

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public function save()
256256
unset($_SESSION[$key]);
257257
}
258258
}
259-
if ([$key = $this->metadataBag->getStorageKey()] === array_keys($_SESSION)) {
259+
if ($_SESSION && [$key = $this->metadataBag->getStorageKey()] === array_keys($_SESSION)) {
260260
unset($_SESSION[$key]);
261261
}
262262

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,13 @@ public function testRegenerateInvalidSessionIdForNativeFileSessionHandler()
321321
$this->assertTrue($started);
322322
$this->assertSame('&~[', session_id());
323323
}
324+
325+
public function testSaveHandlesNullSessionGracefully()
326+
{
327+
$storage = $this->getStorage();
328+
$_SESSION = null;
329+
$storage->save();
330+
331+
$this->addToAssertionCount(1);
332+
}
324333
}

0 commit comments

Comments
 (0)
0