@@ -102,9 +102,12 @@ class NativeSessionStorage implements SessionStorageInterface
102102 */
103103 public function __construct (array $ options = array (), $ handler = null , MetadataBag $ metaBag = null )
104104 {
105+ $ cannotOverrideSessionParameters = \PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE === session_status ();
106+
105107 $ this ->setMetadataBag ($ metaBag );
108+ $ this ->setSaveHandler ($ handler , !$ cannotOverrideSessionParameters );
106109
107- if (\ PHP_VERSION_ID >= 50400 && \ PHP_SESSION_ACTIVE === session_status () ) {
110+ if ($ cannotOverrideSessionParameters ) {
108111 return ;
109112 }
110113
@@ -121,7 +124,6 @@ public function __construct(array $options = array(), $handler = null, MetadataB
121124 }
122125
123126 $ this ->setOptions ($ options );
124- $ this ->setSaveHandler ($ handler );
125127 }
126128
127129 /**
@@ -383,10 +385,11 @@ public function setOptions(array $options)
383385 * @see http://github.com/drak/NativeSession
384386 *
385387 * @param AbstractProxy|NativeSessionHandler|\SessionHandlerInterface|null $saveHandler
388+ * @param bool $updatePhpHandler
386389 *
387390 * @throws \InvalidArgumentException
388391 */
389- public function setSaveHandler ($ saveHandler = null )
392+ public function setSaveHandler ($ saveHandler = null , bool $ updatePhpHandler = true )
390393 {
391394 if (!$ saveHandler instanceof AbstractProxy &&
392395 !$ saveHandler instanceof NativeSessionHandler &&
@@ -408,7 +411,7 @@ public function setSaveHandler($saveHandler = null)
408411 }
409412 $ this ->saveHandler = $ saveHandler ;
410413
411- if ($ this ->saveHandler instanceof \SessionHandlerInterface) {
414+ if ($ this ->saveHandler instanceof \SessionHandlerInterface && $ updatePhpHandler ) {
412415 if (\PHP_VERSION_ID >= 50400 ) {
413416 session_set_save_handler ($ this ->saveHandler , false );
414417 } else {
0 commit comments