Hi everyone,
I'm the author of the Wikilog MediaWiki extension. Today, a user contacted me about an error that MediaWiki is reporting concerning the extension:
Detected bug in an extension! Hook WikilogHooks::UnknownAction failed to return a value; should return true to continue hook processing or false to abort.
Backtrace:
#0 ...\includes\Wiki.php(526): wfRunHooks('UnknownAction', Array) #1 ...\includes\Wiki.php(63): MediaWiki->performAction(Object( OutputPage), Object(WikilogMainPage), Object(Title), Object(User), Object(WebRequest)) #2 ...\index.php(116): MediaWiki->initialize(Object(Title), Object(WikilogMainPage), Object(OutputPage), Object(User), Object(WebRequest)) #3 {main}
The error message seems really obvious, except that there should be no way for the reported function to finish without returning a value. You may check it near the bottom at this address:
http://svn.juliano.info/svn/mediawiki/extensions/Wikilog/tags/0.7.2/WikilogH...
static function UnknownAction( $action, &$article ) { if ( $action == 'wikilog' && $article instanceof WikilogCustomAction ) { $article->wikilog(); return false; } return true; }
I can't see any way that this function would not return either true or false. Needless to say, I can't reproduce this behavior on my own installation.
Does anyone have experienced something similar, or have any idea that could enlighten the situation?
The user's versions:
WinXP with IIS 5. MediaWiki 1.15.1 PHP 5.3.0 (cgi-fcgi) MySQL 5.1.37-community Wikilog 0.7.2, no other extensions
Regards, Juliano.
Juliano F. Ravasi wrote:
Detected bug in an extension! Hook WikilogHooks::UnknownAction failed to return a value; should return true to continue hook processing or false to abort.
Someone reported a similar bug with FlaggedRev (on msusers.com). I didn't look at the code but did express surprise that such a bug would show up in a fairly new and extensively discussed/tested extension.
Maybe there's a bug in PHP 5.3 not tracing the program paths (acyclic graph?) correctly and reporting that error.
Mike
On 8/27/09 5:55 PM, Juliano F. Ravasi wrote:
I'm the author of the Wikilog MediaWiki extension. Today, a user contacted me about an error that MediaWiki is reporting concerning the extension:
Detected bug in an extension! Hook WikilogHooks::UnknownAction failed to return a value; should return true to continue hook processing or false to abort.
[snip]
The error message seems really obvious, except that there should be no way for the reported function to finish without returning a value.
The callback is called via call_user_func_array, which apparently can end up returning null in certain failure cases:
http://bugs.php.net/bug.php?id=47554
You can see an example here where I try passing in an invalid callback (as I don't have the class locally, it's not callable):
var_dump(call_user_func(array('WikilogHooks','UnknownAction')));
Warning: call_user_func(WikilogHooks::UnknownAction): First argument is expected to be a valid callback in /Library/WebServer/Documents/trunk/maintenance/eval.php(60) : eval()'d code on line 1 NULL
That warning message may not be shown depending on PHP's error_log and display_errors settings, leaving only MediaWiki's display of the now-surprising exception about the hook function returning null.
There could be several reasons it's failing:
* something's trashing the $wgAutoloadClasses entries, causing the hooks class to not be loaded (I suspect this is most likely; another extension might be responsible) * missing or damaged WikilogHooks.php file * missing or damaged Wikilog.php file * weird PHP breakage like a borked opcode cache
-- brion
Brion Vibber wrote:
That warning message may not be shown depending on PHP's error_log and display_errors settings, leaving only MediaWiki's display of the now-surprising exception about the hook function returning null.
Pretty much what was happening. It seems that the user had its logs going elsewhere.
The behavior of call_user_func() returning the undocumented NULL was also a problem. This makes difficult to detect different types of bugs. I don't know if it is a good idea to improve the thrown exception message when call_user_func_array() returns null to note this possibility. Or perhaps use set_error_handler() around the call_user_func_array() to catch these types of errors and provide a better error message.
There could be several reasons it's failing:
- something's trashing the $wgAutoloadClasses entries, causing the hooks
class to not be loaded (I suspect this is most likely; another extension might be responsible)
- missing or damaged WikilogHooks.php file
- missing or damaged Wikilog.php file
- weird PHP breakage like a borked opcode cache
I found it, it was a value<->reference incompatibility in the parameter list of the function.
Thanks for the help!
Best regards, Juliano.
Juliano F. Ravasi wrote:
The error message seems really obvious, except that there should be no way for the reported function to finish without returning a value. You may check it near the bottom at this address:
http://svn.juliano.info/svn/mediawiki/extensions/Wikilog/tags/0.7.2/WikilogH...
static function UnknownAction( $action, &$article ) { if ( $action == 'wikilog' && $article instanceof WikilogCustomAction ) { $article->wikilog(); return false; } return true; }
I can't see any way that this function would not return either true or false. Needless to say, I can't reproduce this behavior on my own installation.
Does anyone have experienced something similar, or have any idea that could enlighten the situation?
$article is not passed by reference in the hook call in Wiki.php. I believe PHP < 5.3 would just silently ignore this (converting the reference to a value IIRC), PHP 5.3 throws a warning and skips over the function in a way that breaks the hook call. Removing the & in front of $article should fix it.
The user's versions:
WinXP with IIS 5. MediaWiki 1.15.1 PHP 5.3.0 (cgi-fcgi) MySQL 5.1.37-community Wikilog 0.7.2, no other extensions
Regards, Juliano.
Alex wrote:
$article is not passed by reference in the hook call in Wiki.php. I believe PHP < 5.3 would just silently ignore this (converting the reference to a value IIRC), PHP 5.3 throws a warning and skips over the function in a way that breaks the hook call. Removing the & in front of $article should fix it.
That was it! Thanks!
Best regards, Juliano.
mediawiki-l@lists.wikimedia.org