PHP Warning: Parameter expected to be a reference, value given

Message:

PHP Warning: Parameter 1 to stats_admin_bar_menu() expected to be a reference, value given

Error type: warning

Symptoms:

A warning is displayed even though the function call seems to have the correct number of parameters.

Sample Code:

<?php
function stats_admin_bar_menu( &$wp_admin_bar ) {
// …
}
call_user_func_array(‘stats_admin_bar_menu’, 1);
?>

Cause:

When a function that has one of the parameters defined as a reference is called with constants, this warning is issued.

Fix:

Check where parameters are defined as reference and pay attention on what parameters are sent at the function call. If a parameter is defined as a reference, it must receive a variable and not a constant.

Leave a Reply

Your email address will not be published. Required fields are marked *