Browse Source

Return empty string on non-existent session read()

Joe Biellik 10 years ago
parent
commit
1b0b4fc062
2 changed files with 10 additions and 4 deletions
  1. 8 2
      src/Network/Session/CacheSession.php
  2. 2 2
      src/Network/Session/DatabaseSession.php

+ 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'])) {