diff --git a/core/lib/Drupal/Core/Theme/ThemeManager.php b/core/lib/Drupal/Core/Theme/ThemeManager.php
index 6850fcb..81ae9bf 100644
--- a/core/lib/Drupal/Core/Theme/ThemeManager.php
+++ b/core/lib/Drupal/Core/Theme/ThemeManager.php
@@ -201,9 +201,9 @@ protected function theme($hook, $variables = array()) {
       $element = $variables;
       $variables = array();
       if (isset($info['variables'])) {
-        foreach (array_keys($info['variables']) as $name) {
-          if (isset($element["#$name"]) || array_key_exists("#$name", $element)) {
-            $variables[$name] = $element["#$name"];
+        foreach ($element as $key => $value) {
+          if ($key[0] == '#') {
+            $variables[ltrim($key, '#')] = $value;
           }
         }
       }
