call_integration_hook('integrate_bbc_codes', array(&$codes)) depr. sind PHP5.4?

Started by spaulding2, May 26, 2012, 12:18:28 AM

Previous topic - Next topic

spaulding2

Hi folks,

adding custom buttons/codes to the editor via 'integrate_bbc_buttons'/'integrate_bbc_codes' is no longer working for me, because the call-time pass by reference doesn't work since php5.4:
Quote
bkfake-php at yahoo dot com 14-Mar-2012 05:49
It should be noted that
call_user_func_array('function', array(&$a));
is effectively a call-time pass by reference

it should also be noted that it does not throw any error or warning in any version of php.    PHP 5.4 continues to not throw a warning.    Also, as of PHP 5.4, the var will not be passed by reference.
(Taken from hxxp:php.net [nonactive] manual topic "Passing by reference")

I'm hacking additional codes/buttons into Subs.php/Subs-Editor.php right now. Are there any plans to change the API or is there a less painless workaround?

Thanks in advance,

Matt

Arantor

As I understood it, call-time references don't work but if the function signature itself indicates it accepts references, that should be honoured?

[SiNaN]

Former SMF Core Developer | My Mods | SimplePortal

feline

tested on 5.4.3 .. works


function debug($data)
{
log_error($data);
}
$host = $_SERVER["SERVER_NAME"];
call_user_func_array('debug', array(&$host));

Arantor

Of course it works, you're using it by value. Do it by reference and you'll see that it won't work as expected.

function test($value)
{
  $value++;
}

$value = 1;
call_user_func_array('test', array(&$value));


Even though you're indicating pass-by-reference, it won't be passed by reference and as such $value is 1 after the call is made.

spaulding2

Hi all,

thanks for the replies.

@Arantor:
Yeah, changing the functions signature is the solution, thanks!

@feline:
To come closer to the problems nature:

function worker() {
$log = array();
$log[] = 'top of log';

call_user_func_array('log_error', array(&$log)); //call by reference
show_log($log); /*call by value!*/ }

/*function log_error($db)*/ // - works up to PHP5.3!
function log_error(&$db) /* right signature under PHP5.4 */ {
$db[] = 'Oh Matt, what are you doin?'; }

function show_log($db) {
foreach ($db as $rec) { printf("%s<br />", $rec); } }

echo 'running php5.4<br />'; worker();

emanuele

So, if I understand it correctly, the only solution to this "bug" is to instruct modders to use in their functions the & in front of the variables.
Am I right?


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Arantor

Yes.

Though SMF should really alter calls not to pass by reference anyway...

emanuele

That would make sense too, but probably it will be worked out in 3.0...


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Arantor

At this stage it's not really a big deal, it just means it won't work. Future versions of PHP will undoubtedly set things up to throw errors.

emanuele

Yep, I can imagine.

My idea was: now php 5.4 is something like 0.5%, so not a big deal.
Let's instruct modders to use the proper way (I have to change most of my mods... :P).
By the time the next SMF will be ready (almost) all the mods will work properly and it will be possible to drop the byref without break things too much...and anyway I'm not sure how things will work in 3.0...

In theory we could start dropping the byref from the new hooks in 2.1...that would make it a mixed model but it should ensure people face the problem and try to fix it... :P


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Arantor

The sad part is that you can lead a horse to water... you can't make 'em drink. There's still going to be problems, whatever happens, but I think the proper course of action would be for SMF to change it in 2.1 so modders learn to get things right sooner rather than later.

4LP3RUZ1

Didn't want to start a new topic since problem is the same and its not a biggie.

I was testing 2.1 on the php 5.4 server i have, and message index listing threw server errors.

So I changed this line in MessageIndex.php to pass by value:

// Allow adding new buttons easily.
// Note: $context['normal_buttons'] is added for backward compatibility with 2.0, but is deprecated and should not be used
call_integration_hook('integrate_messageindex_buttons', &$context['normal_buttons']);


things went smoothly after that. Did I break anything?
Frozen frogs are back :(


4LP3RUZ1

Frozen frogs are back :(

Advertisement: