Pass data from a hook to (be used in another hook) So in a hook hook_commerce_cart_order_refresh() I make some calculations that I would later like to use in a different hook hook_form_alter, how can I pass these data/object and use later on?

In that first hook, I have a EntityMetadataWrapper but it seems I can only give it data that actually is persisted, and mine should only exist for the request.

Again, I could use $_SESSION but that storage is used for persistent storage through multiple requests. And I'm not looking for that.

Any suggestions?
You can't, there's no mechanism to pass data from one arbitrary function to another (which is what two separate hooks essentially are). You'll have to make the data available another way.

Drupal uses a pattern like this all over the place:

function MYMODULE_get_data() {
  $data = &amp;drupal_static(__FUNCTION__, NULL);

  if (!$data) {
    $data = some_function_to_build_data();
  }

  return $data;
}

function MYMODULE_commerce_cart_order_refresh(...) {
  // Get the data, populating it if it doesn't already exist.
  $data = MYMODULE_get_data();
}

function MYMODULE_form_alter(...) {
  // Retrieve the data.
  $data = MYMODULE_get_data();
}


That's a contrived example, it'll make more sense when you plug your own requirements into it.