Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.370
diff -u -p -r1.370 bootstrap.inc
--- includes/bootstrap.inc	7 Apr 2010 05:15:50 -0000	1.370
+++ includes/bootstrap.inc	11 Apr 2010 19:19:39 -0000
@@ -2594,34 +2594,35 @@ function registry_update() {
  */
 function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
   static $data = array(), $default = array();
-  if (!isset($name)) {
-    // All variables are reset. This needs to be done one at a time so that
-    // references returned by earlier invocations of drupal_static() also get
-    // reset.
-    foreach ($default as $name => $value) {
-      $data[$name] = $value;
-    }
-    // As the function returns a reference, the return should always be a
-    // variable.
-    return $data;
-  }
-  if ($reset) {
-    // The reset means the default is loaded.
-    if (array_key_exists($name, $default)) {
+  // First check if dealing with a previously defined static variable.
+  if (array_key_exists($name, $data)) {
+    // Non-NULL $name and both $data[$name] and $default[$name] statics exist.
+    if ($reset) {
+      // Reset pre-existing static variable to its default value.
       $data[$name] = $default[$name];
     }
-    else {
+    return $data[$name];
+  }
+  // Neither $data[$name] nor $default[$name] static variables exist.
+  if (isset($name)) {
+    if ($reset) {
       // Reset was called before a default is set and yet a variable must be
       // returned.
       return $data;
     }
-  }
-  elseif (!array_key_exists($name, $data)) {
-    // Store the default value internally and also copy it to the reference to
-    // be returned.
+    // First call with new non-NULL $name. Initialize a new static variable.
     $default[$name] = $data[$name] = $default_value;
+    return $data[$name];
   }
-  return $data[$name];
+  // Reset all: ($name == NULL). This needs to be done one at a time so that
+  // references returned by earlier invocations of drupal_static() also get
+  // reset.
+  foreach ($default as $name => $value) {
+    $data[$name] = $value;
+  }
+  // As the function returns a reference, the return should always be a
+  // variable.
+  return $data;
 }
 
 /**
