diff --git a/src/SessionManager.php b/src/SessionManager.php index bf779907..26690512 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -93,7 +93,10 @@ public function start($preserveStorage = false) $this->registerSaveHandler($saveHandler); } - $oldSessionData = $_SESSION; + $oldSessionData = array(); + if (isset($_SESSION)) { + $oldSessionData = $_SESSION; + } session_start(); diff --git a/test/Service/SessionManagerFactoryTest.php b/test/Service/SessionManagerFactoryTest.php index fee441ba..5a2fc0c8 100644 --- a/test/Service/SessionManagerFactoryTest.php +++ b/test/Service/SessionManagerFactoryTest.php @@ -87,4 +87,18 @@ public function testFactoryWillAddValidatorViaConfiguration() $this->assertEquals(1, $manager->getValidatorChain()->getListeners('session.validate')->count()); } + + /** + * @runInSeparateProcess + */ + public function testStartingSessionManagerFromFactoryDoesNotTriggerUndefinedVariable() + { + $storage = new ArrayStorage(); + $this->services->setService('Zend\Session\Storage\StorageInterface', $storage); + + $manager = $this->services->get('Zend\Session\ManagerInterface'); + $manager->start(); + + $this->assertSame($storage, $manager->getStorage()); + } }