Skip to content

Commit 05f3e77

Browse files
committed
[HttpFoundation] Fix TypeError on null $_SESSION in NativeSessionStorage::save()
1 parent 2c26d24 commit 05f3e77

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)