1

I have a custom module that adds a couple action links via menu items:

function monographs_menu() {
  $items['node/%node/clone_comment'] = array(
    'access callback' => 'clone_access_cloning',
    'access arguments' => array(1),
    'page callback' => 'monographs_node_check',
    'page arguments' => array(1, 2),
    'title' => 'Create For Comment version',
    'type' => MENU_LOCAL_ACTION,
  );

  $items['node/%node/clone_authorized'] = array(
    'access callback' => 'clone_access_cloning',
    'access arguments' => array(1),
    'page callback' => 'monographs_node_check',
    'page arguments' => array(1, 2),
    'title' => 'Create Final Authorized version',
    'type' => MENU_LOCAL_ACTION,
  );

  return $items; 
}

and the function signature for the page callback is

function monographs_node_check(&$node, $type)

On my local machine and my dev server, this all works just peachy. However, on the client's server, with a clone of my db and the repo, whenever this link is clicked on, they get a WSOD and this error in watchdog:

Warning: Parameter 1 to monographs_node_check() expected to be a reference, value given in menu_execute_active_handler() (line 517 of ...\public_html\includes\menu.inc).

Since it's on a remote server that I don't have access to, I can't debug it, but the fact that it works without error on my own local machine and dev server makes it even weirder.

What could be different in the other environment that would cause this error?

Thanks.

2

I got the answer from the support list, and all I needed to do was remove the reference for the node object in my callback function signature:

function monographs_node_check($node, $type)

$node is passed as an object anyway, so I don't need to mark it as being by reference in the signature.

1

The problem occurs because Drupal uses call_user_func_array() in order to invoke the menu callback function and pass the parameters to it.

If your function signature is:

function monographs_node_check(&$node, $type)

Then a call to call_user_func_array() must look like this:

call_user_func_array('monographs_node_check', array(&$node, $type));

The important thing to note is that the pass-by-reference is explicitly set on the caller side by using &$node, as well as in the called function's declaration.

This has apparently always been true since PHP 4.

Since Drupal does not pass any of these parameters to call_user_func_array() be reference in this situation, you get an error.

The most likely reason you're getting the error on one server and not the other is that you have different versions of PHP on each; prior to PHP 5.3.0 this was handled silently instead of raising an error. Now the upshot of the error is that the function is never actually invoked, so your page will never display.

There's a good discussion on the matter in this PHP bug report.

  • That doesn't make sense to me, because I've seen many errors of "Call time pass by reference deprecated" (my paraphrase) when trying to pass something by reference in the function call, not just the function signature. But even with that, how can I fix this problem, since I'm not implementing call_user_func_array myself, I'm just implementing a menu callback? – wonder95 Mar 1 '12 at 22:35
  • Those are two different errors; you're not passing a parameter by reference directly to call_user_func_array(), you're passing the array, by value. If you want the invoked function to take an argument by reference, the value inside the arguments array also needs to be passed by reference. Object are usually passed by reference in PHP anyway so you should be able to just change the function signature to function monographs_node_check($node, $type) – Clive Mar 1 '12 at 22:57
  • 1
    As @Clive said, you must not have by reference arguments in menu callbacks or theme functions, that doesn't work and makes no sense. Note that objects are always by-reference (something similar, at least) in PHP 5. – Berdir Mar 2 '12 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.