diff --git a/lib/SimpleSAML/Memcache.php b/lib/SimpleSAML/Memcache.php
index ea8e9b175af5144acc5d9920444e2174a22b960d..adb3ab0ed01d3b22dedd525fdef3af01318cc284 100644
--- a/lib/SimpleSAML/Memcache.php
+++ b/lib/SimpleSAML/Memcache.php
@@ -336,11 +336,6 @@ class Memcache
 
         // iterate over all the groups in the 'memcache_store.servers' configuration option
         foreach ($groups as $index => $group) {
-            // make sure that the group doesn't have an index. An index would be a sign of invalid configuration
-            if (is_int($index)) {
-                $index = null;
-            }
-
             /*
              * Make sure that the group is an array. Each group is an array of servers. Each server is
              * an array of name => value pairs for that server.
@@ -353,6 +348,11 @@ class Memcache
                 );
             }
 
+            // make sure that the group doesn't have an index. An index would be a sign of invalid configuration
+            if (is_int($index)) {
+                $index = null;
+            }
+
             // parse and add this group to the server group list
             self::$serverGroups[] = self::loadMemcacheServerGroup($group, $index);
         }