Advertisement:
2by2host

Author Topic: call_integration_hook('integrate_bbc_codes', array(&$codes)) depr. sind PHP5.4?  (Read 2971 times)

Offline spaulding2

  • Newbie
  • *
  • Posts: 2
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 php.net 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
 
« Last Edit: May 26, 2012, 12:30:32 AM by spaulding2 »

Offline Arantor

  • SMF Legend
  • *********
  • Posts: 51,160
    • wedgebook on Facebook
As I understood it, call-time references don't work but if the function signature itself indicates it accepts references, that should be honoured?

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,503
  • Young and Foolish
    • SimplePortal
Yeah, I think that should work.
Former SMF Core Developer | My Mods | My Anime List | SimplePortal | Samanyolu Fanları

Offline feline

  • Beta Tester
  • SMF Hero
  • *
  • Posts: 1,514
  • Gender: Female
    • Product developer site
tested on 5.4.3 .. works

Code: [Select]
function debug($data)
{
log_error($data);
}
$host = $_SERVER["SERVER_NAME"];
call_user_func_array('debug', array(&$host));
PortaMx has released version 1.51 for SMF 2 with a built in SEF engine, full support for the EU Cookie Law and a lot of new features. Follow us on our Community


Offline Arantor

  • SMF Legend
  • *********
  • Posts: 51,160
    • wedgebook on Facebook
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.

Code: [Select]
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.

Offline spaulding2

  • Newbie
  • *
  • Posts: 2
Hi all,

thanks for the replies.

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

@feline:
To come closer to the problems nature:
Code: [Select]
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();
« Last Edit: May 27, 2012, 04:18:39 AM by spaulding2 »

Offline emanuele

  • Developer
  • SMF Super Hero
  • *
  • Posts: 12,154
  • Gender: Male
  • Because Orange is Orange
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?

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

Offline Arantor

  • SMF Legend
  • *********
  • Posts: 51,160
    • wedgebook on Facebook
Yes.

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

Offline emanuele

  • Developer
  • SMF Super Hero
  • *
  • Posts: 12,154
  • Gender: Male
  • Because Orange is Orange
That would make sense too, but probably it will be worked out in 3.0...

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

Offline Arantor

  • SMF Legend
  • *********
  • Posts: 51,160
    • wedgebook on Facebook
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.

Offline emanuele

  • Developer
  • SMF Super Hero
  • *
  • Posts: 12,154
  • Gender: Male
  • Because Orange is Orange
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

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

Offline Arantor

  • SMF Legend
  • *********
  • Posts: 51,160
    • wedgebook on Facebook
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.

Offline 4LP3RUZ1

  • SMF Hero
  • ******
  • Posts: 3,416
  • Gender: Male
  • I don't like frozen frogs :(
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:
Code: [Select]
// 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?

Offline live627

  • SMF Hero
  • ******
  • Posts: 3,332
  • Gender: Male
  • A light for our dream which is worth everything we could envision today and more tomorrow
    • live627 on Facebook
    • @live627 on Twitter
    • livemods
Quote
Did I break anything?
No
See a list of my mods

I don't accept support PMs. Ever! Your query will be answered much quicker in the public boards. Why don't I want any PMs asking for support?

Offline 4LP3RUZ1

  • SMF Hero
  • ******
  • Posts: 3,416
  • Gender: Male
  • I don't like frozen frogs :(
Quote
Did I break anything?
No
Ok,

Thanks!