diff --git a/lib/SimpleSAML/SessionHandlerPHP.php b/lib/SimpleSAML/SessionHandlerPHP.php
index 6a2eae69b4c46c72b4cb78d3bc946510fabc23a3..80dab625447503c9578c9b183585d875828db287 100644
--- a/lib/SimpleSAML/SessionHandlerPHP.php
+++ b/lib/SimpleSAML/SessionHandlerPHP.php
@@ -83,6 +83,7 @@ class SimpleSAML_SessionHandlerPHP extends SimpleSAML_SessionHandler {
 		/* Check if key exists first to avoid notice-messages in the
 		 * log.
 		 */
+		if (!isset($_SESSION)) return NULL;
 		if(!array_key_exists($key, $_SESSION)) {
 			/* We should return NULL if we don't have that
 			 * key in the session.