In a custom module, get return of hook for making it available in other hook I had some similar questions here, but would like ultimately to know best practices and possibilities for this case.

I have my custom module, in which I use two contrib modules hooks. As I understood, hooks are self-invoked (looking from my module point of view), and as soon as I am declaring it, they get executed.

That said, how I can get return of an hook function ?

I am trying to make $foo1 available in other hook and vice versa for $hook2. I would like to avoid oop solutions if possible. 

Example:

function mymodule_contribmodulehook1 ($parameter1, $parameter2) {
  //$foo2 here somehow ? 
  $foo1 = 1;
  return $foo1; 
}

function mymodule_contribmodulehook2 ($parameter1, $parameter2) {
  //$foo1 here somehow ?
  $foo2 = 1;
  return $foo2; 
}
Yes, if you implement a hook provided by a contrib module, it is invoked by that module function.
You can declare those two variables in global scope so that they can be accessible each other in the functions.

&lt;?php
// mymodule.module
global $foo1;
global $foo2;

function mymodule_contribmodulehook1 ($parameter1, $parameter2) {
  global $foo2;
  //$foo2 here 
  $foo1 = 1;
}

function mymodule_contribmodulehook2 ($parameter1, $parameter2) {
  global $foo1;
  //$foo1 here
  $foo2 = 1;
}


If you don't want to use global scope for your variables, you can save and retrieve them alternatively in your Drupal database using variable_set() and variable_get().

function mymodule_contribmodulehook1 ($parameter1, $parameter2) {
  $foo2 = variable_get('foo2');
  $foo1 = 1; 
  variable_set('foo1', $foo1);
}

function mymodule_contribmodulehook2 ($parameter1, $parameter2) {
  $foo1 = variable_get('foo1'); 
  $foo2 = 1;
  variable_set('foo2', $foo2);
}


Note that, for both approaches, you don't need to return each of them as long as you don't have any other purpose.