]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Session.php
Cleanups: isResult() more used, readability improved (#5608)
[friendica.git] / src / Core / Session.php
index b245c675b0f0981f7d0a759e2fbb2cb5ac4065de..6d059eb4ef5de1d4d69237bdda0aac7bb0817657 100644 (file)
@@ -45,9 +45,24 @@ class Session
                return isset($_SESSION[$name]);
        }
 
-       public static function get($name)
+       /**
+        * Retrieves a key from the session super global or the defaults if the key is missing or the value is falsy.
+        * 
+        * Handle the case where session_start() hasn't been called and the super global isn't available.
+        *
+        * @param string $name
+        * @param mixed $defaults
+        * @return mixed
+        */
+       public static function get($name, $defaults = null)
        {
-               return defaults($_SESSION, $name, null);
+               if (isset($_SESSION)) {
+                       $return = defaults($_SESSION, $name, $defaults);
+               } else {
+                       $return = $defaults;
+               }
+
+               return $return;
        }
 
        public static function set($name, $value)