[Mediawiki-l] PHP 5.3 update and MediaWiki hook return values?

Brion Vibber brion at pobox.com
Mon Apr 11 19:32:10 UTC 2011


On Mon, Apr 11, 2011 at 11:52 AM, Daniel Barrett <danb at vistaprint.com>wrote:

> I updated our wiki server (1.16.2) from PHP 5.1.6 to PHP 5.3.3, and now
> MediaWiki is complaining about extensions not returning values in their hook
> functions, when they are definitely returning "true". Does this look
> familiar to anybody?
>
> Example:
>
>      $wgHooks['SkinAfterBottomScripts'][] = 'MyClass::addBottomScripts';
>
>      class MyClass {
>              static function addBottomScripts( &$sk, &$bottomScriptText ) {
>                      return true;
>              }
>      }
>

See http://bugs.php.net/bug.php?id=47554 -- the hook call via
call_user_func_array() can actually return null for some error cases, where
the callback is invalid or uncallable for some reason like parameter
validation.

In this case, it's likely failing because PHP 5.3 is much stricter about
references, especially on function parameters. Your hook is declaring the
$sk parameter as a reference (&$sk) but the call is not passing it as a
reference:

  wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText )
);

Your PHP or web server error log might include a warning about this; make
sure you at least have warnings and errors going to a log if you've disabled
PHP's display_errors setting. The use of references there probably dates
back to PHP 4.x coding practices in early MediaWiki, and should be removed.
(The second parameter really is a reference parameter so the string can be
modified, so be sure to keep that one!)

Try removing the & reference marker on your function declaration and see if
that clears it up.

-- brion


More information about the MediaWiki-l mailing list