8000 When session is active, do not change options with PHP 7.2 · symfony/symfony@a930a67 · GitHub
[go: up one dir, main page]

Skip to content

Commit a930a67

Browse files
committed
When session is active, do not change options with PHP 7.2
1 parent cfb86c0 commit a930a67

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,23 @@ public function __construct(array $options = array(), $handler = null, MetadataB
105105
$this->setMetadataBag($metaBag);
106106

107107
if (PHP_VERSION_ID >= 70200 && \PHP_SESSION_ACTIVE === session_status()) {
108-
if (!empty($options) || null !== $handler) {
109-
throw new \LogicException('Cannot change options or handler of an active session');
110-
}
111-
} else {
112-
$options += array(
113-
// disable by default because it's managed by HeaderBag (if used)
114-
'cache_limiter' => '',
115-
'use_cookies' => 1,
116-
);
108+
return;
109+
}
117110

118-
if (\PHP_VERSION_ID >= 50400) {
119-
session_register_shutdown();
120-
} else {
121-
register_shutdown_function('session_write_close');
122-
}
111+
$options += array(
112+
// disable by default because it's managed by HeaderBag (if used)
113+
'cache_limiter' => '',
114+
'use_cookies' => 1,
115+
);
123116

124-
$this->setOptions($options);
125-
$this->setSaveHandler($handler);
117+
if (\PHP_VERSION_ID >= 50400) {
118+
session_register_shutdown();
119+
} else {
120+
register_shutdown_function('session_write_close');
126121
}
122+
123+
$this->setOptions($options);
124+
$this->setSaveHandler($handler);
127125
}
128126

129127
/**

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,16 @@ public function testCanCreateNativeSessionStorageWhenSessionAlreadyStarted()
283283
}
284284

285285
/**
286-
* @expectedException \LogicException
286+
* @requires PHP 7.2
287287
*/
288-
public function testCannotSetSessionOptionsOnceSessionStarted()
288+
public function testSetSessionOptionsOnceSessionStartedIsIgnored()
289289
{
290-
if (PHP_VERSION_ID < 70200) {
291-
$this->markTestSkipped('Limitation from PHP 7.2 only');
292-
}
293-
294290
session_start();
295291
$this->getStorage(array(
296292
'name' => 'something-else',
297293
));
294+
295+
// Assert no exception has been thrown by `getStorage()`
296+
$this->assertTrue(true);
298297
}
299298
}

0 commit comments

Comments
 (0)
0