You are here

function messaging_static in Messaging 6.4

Same name and namespace in other branches
  1. 6.3 messaging.module \messaging_static()

Central static variable storage, Drupal 7 core backport

See http://api.drupal.org/api/function/drupal_static/7

10 calls to messaging_static()
messaging_info in ./messaging.module
Invoke hook_notifications($name) on all modules
messaging_load_user in ./messaging.module
Helper user loading function with static caching
messaging_send_method in ./messaging.module
Get send method object
messaging_static_cache_get in ./messaging.module
Get data from static cache
messaging_static_cache_set in ./messaging.module
Set data on static cache, checking whether the cache is under limits.

... See full list

File

./messaging.module, line 1134

Code

function &messaging_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)) {
      $data[$name] = $default[$name];
    }
    else {

      // 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.
    $default[$name] = $data[$name] = $default_value;
  }
  return $data[$name];
}