Pass parameter from a custom php function to hook_block I have a hook_menu page callback. I want to use the argument which it receives in hook_block.

For example

function myCustomFunction($args) {

}

modulename_block() {
  // Use $args here
}


How can this be done. Is there a way I can pass this as a parameter.
I'm not sure how this would be expected to work consistently; if your block relies on arguments built up from a particular page callback, then the block will only work on that page.

Having said that, if the page callback arguments are based on a known value, for example a node ID, then I can see how it might work for a particular path/set of paths.

Let's say this is your menu item in hook_menu():

$items['my/path/%node'] = array(
  'title' =&gt; 'A title',
  'access arguments' =&gt; array('access content'),
  'page callback' =&gt; 'MYMODULE_some_function',
  'page arguments' =&gt; array(2)
);


And this is your code for MYMODULE_some_function():

function MYMODULE_some_function($node) {
  $the_value = do_something_to($node);
}


In your hook_block() function you can grab the node ID out of the URL, load the node manually, and perform the same function on it that you have in MYMODULE_some_function(). For example:

function MYMODULE_block($op = 'list', $delta = 0, $edit = array()) {
  // I've omitted the 'list' op, obviously you'll need to implement that yourself

  if ($op == 'view' &amp;&amp; $delta == $the_delta) {
    // Check that we're on an appropriate page
    if (arg(0) == 'my' &amp;&amp; arg(1) == 'path' &amp;&amp; is_numeric(arg(2))) {
      $nid = arg(2);

      $node = node_load($nid);

      $the_value = do_something_to($node);

      $block['content'] = $the_value;
    }
  }
}


You might want to centralise the code that runs $the_value = do_something_to($node); into it's own function so you're not repeating yourself.