diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index f65ab4c..8cf4b7a 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -3158,6 +3158,11 @@ function registry_update() { * distinguishing suffix to the function name for each one. * @param $default_value * Optional default value. + * @param bool $persistent + * (optional) Whether the statically cached value should persist across + * sub-requests initiated by DrupalKernel. Defaults to FALSE. Only use TRUE + * for values that are not specific to the request in any way; e.g., module + * information, theme registry, etc. * @param $reset * TRUE to reset a specific named variable, or all variables if $name is NULL. * Resetting every variable should only be used, for example, for running @@ -3170,37 +3175,37 @@ function registry_update() { * * @see drupal_static_reset() */ -function &drupal_static($name, $default_value = NULL, $reset = FALSE) { - static $data = array(), $default = array(); +function &drupal_static($name, $default_value = NULL, $persistent = FALSE, $reset = FALSE) { + static $data = array(FALSE => array(), TRUE => array()), $default = array(); // First check if dealing with a previously defined static variable. - if (isset($data[$name]) || array_key_exists($name, $data)) { + if (isset($data[$persistent][$name]) || array_key_exists($name, $data[$persistent])) { // 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]; + $data[$persistent][$name] = $default[$name]; } - return $data[$name]; + return $data[$persistent][$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; + return $data[$persistent]; } // First call with new non-NULL $name. Initialize a new static variable. - $default[$name] = $data[$name] = $default_value; - return $data[$name]; + $default[$name] = $data[$persistent][$name] = $default_value; + return $data[$persistent][$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; + $data[$persistent][$name] = $value; } // As the function returns a reference, the return should always be a // variable. - return $data; + return $data[$persistent]; } /** @@ -3208,9 +3213,15 @@ function &drupal_static($name, $default_value = NULL, $reset = FALSE) { * * @param $name * Name of the static variable to reset. Omit to reset all variables. + * @param bool $include_persistent + * (optional) Pass TRUE to also reset static variables that persist across + * sub-requests. Defaults to FALSE. */ -function drupal_static_reset($name = NULL) { - drupal_static($name, NULL, TRUE); +function drupal_static_reset($name = NULL, $include_persistent = FALSE) { + drupal_static($name, NULL, FALSE, TRUE); + if ($include_persistent) { + drupal_static($name, NULL, TRUE, TRUE); + } } /**