Q:

Share a value between two different hooks

I have 2 hook functions in my module: hook_views_pre_render() and hook_form_alter(); in hook_views_pre_render(), I retrieve some data about what nodes that are available that I need in hook_form_alter().
I'm looking for a way to pass the data from hook_views_pre_render() to hook_form_alter(). It seems simple, but I can't get it to work. Does anyone any idea?
What works for the moment is to add global $aVariable to both the hook functions, but I believe there should be a better way.

A:

In Drupal 7, drupal_static() could be used too, if the stored value doesn't need to be persistent between different pages.
drupal_static() is normally called as drupal_static(__FUNCTION__, $default_value), but if you use the name of the function, you can access the same value accessed from the function that calls drupal_static().
Using variable_set() and variable_get() the value is persistent between different pages, and it is not automatically removed. If the first hook execute code similar to the following one, then the second module would get an older value.
if ($condition) {
  variable_set($variable_name, $value);
}

Rather than using such code, the first hook should execute code similar to the following one.
if ($condition) {
  variable_set($variable_name, $value);
}
else {
  variable_del($variable_name);
}

Whatever method you choose, be sure the hook reading the value is effectively running after the hook setting that value.

A:

you can use variable_set($name, $value) and variable_get($name, $default = NULL)

