PHP 5.4 bug, mods/plugins with hooks

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
PHP 5.4 bug, mods/plugins with hooks
« on May 27th, 2012, 03:17 PM »
So, I've been watching this for a while, ever since I heard that PHP 5.4 would deprecate call-time pass-by-reference, knowing full well that both SMF and Wedge's hook caller uses this.

I was not surprised to discover there were issues, nor was I surprised to note what the issues were, and now that I think about it, I was not surprised to note that my observation was entirely correct.

OK, here's the deal. When a hook is called, normally all the variables are shoved through call_user_func_array by reference. As of PHP 5.4, that won't work as expected.

Specifically, it won't work if the receiving function's signature doesn't state it's expecting things as references. Which meant that most of the mods written using hooks actually didn't work properly under PHP 5.4, though oddly enough this was never an issue for mine, because I always indicated everything should be by-reference anyway in the signatures, I found it a good practice to get into.

What that also means we should probably strip all the & signs from call_hook calls, because in both 5.3 and 5.4, the function's signature should be indicative of receiving-by-reference and in both cases it should be honoured.

In any case, any plugin using hooks should note that all variables received, that are intended to be modified in place should be indicated in the function xyz() definition as function xyz(&$variable) not function xyz($variable).
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
Re: PHP 5.4 bug, mods/plugins with hooks
« Reply #1, on May 27th, 2012, 07:12 PM »
All my plugins do that - for the very reason mentioned. Plus I wasn't  sure  if things would work without them.
A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.

Nao

  • Dadman with a boy
  • Posts: 16,079

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670

Nao

  • Dadman with a boy
  • Posts: 16,079

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278