Browse Source

Merge pull request #7867 from JoeBiellik/master

Fix session regeneration on PHP 7
Mark Story 10 years ago
parent
commit
4a71ab9c9f

+ 8 - 2
src/Network/Session/CacheSession.php

@@ -78,11 +78,17 @@ class CacheSession implements SessionHandlerInterface
      * Method used to read from a cache session.
      *
      * @param string $id The key of the value to read
-     * @return mixed The value of the key or false if it does not exist
+     * @return string The value of the key or empty if it does not exist
      */
     public function read($id)
     {
-        return Cache::read($id, $this->_options['config']);
+        $value = Cache::read($id, $this->_options['config']);
+
+        if (empty($value)) {
+            return '';
+        }
+
+        return $value;
     }
 
     /**

+ 2 - 2
src/Network/Session/DatabaseSession.php

@@ -89,7 +89,7 @@ class DatabaseSession implements SessionHandlerInterface
      * Method used to read from a database session.
      *
      * @param int|string $id The key of the value to read
-     * @return mixed The value of the key or false if it does not exist
+     * @return string The value of the key or empty if it does not exist
      */
     public function read($id)
     {
@@ -101,7 +101,7 @@ class DatabaseSession implements SessionHandlerInterface
             ->first();
 
         if (empty($result)) {
-            return false;
+            return '';
         }
 
         if (is_string($result['data'])) {

+ 3 - 3
tests/TestCase/Network/Session/DatabaseSessionTest.php

@@ -130,7 +130,7 @@ class DatabaseSessionTest extends TestCase
         $this->assertEquals($expected, $result);
 
         $result = $this->storage->read('made up value');
-        $this->assertFalse($result);
+        $this->assertEmpty($result);
     }
 
     /**
@@ -143,7 +143,7 @@ class DatabaseSessionTest extends TestCase
         $this->storage->write('foo', 'Some value');
 
         $this->assertTrue($this->storage->destroy('foo'), 'Destroy failed');
-        $this->assertFalse($this->storage->read('foo'), 'Value still present.');
+        $this->assertEmpty($this->storage->read('foo'), 'Value still present.');
     }
 
     /**
@@ -161,7 +161,7 @@ class DatabaseSessionTest extends TestCase
 
         sleep(1);
         $storage->gc(0);
-        $this->assertFalse($storage->read('foo'));
+        $this->assertEmpty($storage->read('foo'));
     }
 
     /**