@@ -103,8 +103,9 @@ class NativeSessionStorage implements SessionStorageInterface
103
103
public function __construct (array $ options = array (), $ handler = null , MetadataBag $ metaBag = null )
104
104
{
105
105
$ this ->setMetadataBag ($ metaBag );
106
+ $ this ->setSaveHandler ($ handler );
106
107
107
- if (\ PHP_VERSION_ID >= 50400 && \ PHP_SESSION_ACTIVE === session_status ()) {
108
+ if (! $ this -> canUpdatePhpSession ()) {
108
109
return ;
109
110
}
110
111
@@ -121,7 +122,6 @@ public function __construct(array $options = array(), $handler = null, MetadataB
121
122
}
122
123
123
124
$ this ->setOptions ($ options );
124
- $ this ->setSaveHandler ($ handler );
125
125
}
126
126
127
127
/**
@@ -383,6 +383,7 @@ public function setOptions(array $options)
383
383
* @see http://github.com/drak/NativeSession
384
384
*
385
385
* @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $saveHandler
386
+ * @param bool $updatePhpHandler
386
387
*
387
388
* @throws \InvalidArgumentException
388
389
*/
@@ -408,7 +409,7 @@ public function setSaveHandler($saveHandler = null)
408
409
}
409
410
$ this ->saveHandler = $ saveHandler ;
410
411
411
- if ($ this ->saveHandler instanceof \SessionHandlerInterface) {
412
+ if ($ this ->saveHandler instanceof \SessionHandlerInterface && $ this -> canUpdatePhpSession () ) {
412
413
if (\PHP_VERSION_ID >= 50400 ) {
413
414
session_set_save_handler ($ this ->saveHandler , false );
414
415
} else {
@@ -449,4 +450,14 @@ protected function loadSession(array &$session = null)
449
450
$ this ->started = true ;
450
451
$ this ->closed = false ;
451
452
}
453
+
454
+ /**
455
+ * Return true if we can update PHP's session.
456
+ *
457
+ * @return bool
458
+ */
459
+ private function canUpdatePhpSession (): bool
460
+ {
461
+ return \PHP_VERSION_ID <= 50400 || \PHP_SESSION_ACTIVE !== session_status ();
462
+ }
452
463
}
0 commit comments