Problem/Motivation

On a site using organic groups and views bulk operations when adding a group to an existing node the following error occurs:

warning: Parameter 2 to og_add_group_action_submit() expected to be a reference, value given in views_bulk_operations.module on line 1967

proceeding to confirm the operation results in duplicate entry in vbo listing.

Not sure of the cause of this issue and wondering if it is related to use of php 7.3+ and still need to investigate it further.

Steps to reproduce

As above.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

izmeez created an issue. See original summary.

izmeez’s picture

Title: [views_bulk_operations] » [views_bulk_operations] warning parameter expected to be a reference, value given ...

Issue title accidentally left incomplete, now updated.

izmeez’s picture

The line this warning points to is the last line of the helper function:

/**
 * Helper function to let the configurable action process the configuration form.
 */
function _views_bulk_operations_action_submit($action, $form, &$form_state) {
  $action_submit = $action['callback'] . '_submit';
  return call_user_func($action_submit, $form, $form_state);
}

leading me to wonder if it is related to the changes introduced in #3022040: [views_bulk_operations] php strict warnings that only apply when changes are made to views-6.x-2.x described in that issue.

roderik’s picture

It's a different cause.

Issue

function og_add_group_action_submit($form, &$form_state) { cannot* be called with call_user_func() - because call_user_func() always passes arguments by value, never by reference. Which doesn't work for the function definition which wants a reference -> it complains*.

* From memory: I think this is the case since PHP5.4 because that was the version that changed things around references. Or was it 5.3?

Solution

Change call_user_func($action_submit, $form, $form_state); to $action_submit($form, $form_state);.

There's no reason for using call_user_func(), basically. (call_user_func_array() has its use because it has a variable number of parameters. With a fixed number of parameters, you can just call a variable function.)

I haven't tried this myself, but it is supported by

  • a vague memory of making many similar changes in PHP5.3/4 times
  • results I see when googling "php variable function vs call_user_func"
izmeez’s picture

Status: Active » Needs review
StatusFileSize
new530 bytes

@roderik Thank you for taking a look at this. Attached is a patch as you suggested and with php 7.3 it appears to resolve the warning. I assume this is a patch that other users of vbo may need to consider.

The other issue, that of duplicate entries in the view after executing the addition of another group is indeed related to the need to ensure the view has the distinct setting enabled.

roderik’s picture

Status: Needs review » Reviewed & tested by the community

Between the two of us, your testing and the undisputed fact that call_user_func($function, ...) can always be replaced by $function(...) (regardless of PHP version)... this is enough for me to set RTBC.

izmeez’s picture

Thanks. I'm happy to have one more warning crushed which might raise it's head as a fatal error with php 8 and really appreciate having someone else to bounce things off. At least it's here for anyone else who comes looking and maybe it will find it's way into the module. Not something we need to hold our breath for thanks to drush make.

dsnopek’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.