drupal_static

function drupal_static

&drupal_static($name, $default_value = NULL, $reset = FALSE)

Provides central static variable storage.

All functions requiring a static variable to persist or cache data within a single page request are encouraged to use this function unless it is absolutely certain that the static variable will not need to be reset during the page request. By centralizing static variable storage through this function, other functions can rely on a consistent API for resetting any other function's static variables.

Example:

function example_list($field = 'default') {
  $examples = &drupal_static(__FUNCTION__);
  if (!isset($examples)) {
    // If this function is being called for the first time after a reset,
    // query the database and execute any other code needed to retrieve
    // information.
    ...
  }
  if (!isset($examples[$field])) {
    // If