Last modified: 2010-05-15 15:33:58 UTC

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
Bug 1694 - Var-args format for wfRunHooks() doesn't allow modifying params
Var-args format for wfRunHooks() doesn't allow modifying params
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
General/Unknown (Other open bugs)
1.4.x
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-03-13 15:49 UTC by Evan Prodromou
Modified: 2010-05-15 15:33 UTC (History)
0 users

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Evan Prodromou 2005-03-13 15:49:55 UTC
The problem is with Hooks.php, the event-handling mechanism for
optional functionality and third-party extensions. wfRunHooks(), the
interface for mainline code to raise events for hooks to handle,
uses PHP's variable-argument syntax. This is so you can give different
parameter sets to different events:

    wfRunHooks('Event1', $param1, $param2, $param3); # three params
    wfRunHooks('Event2', $param4, $param5); # just two params

The problem with this is that the var args syntax silently changes
pass-by-reference semantics to pass-by-value semantics. So events that
should allow modifying parameters do not. For example:

    $wgEventHooks['Event3'][] = 'MyEvent3Handler';
    # ...
    function MyEvent3Handler(&$str) {
        $str .= " and so on.";
        return true;
        }
    # ...
    $somestring = "Eggs, bananas, bacon";
    # NOTE: OLD CALLING FORMAT
    if (wfRunHooks('Event3', &$somestring)) {
        echo $somestring; # prints "Eggs, bananas, bacon"
    }

After some consulting with PHP gurus, the best solution I could come up
with was to pack the params in an array when passing them to
wfRunHooks(). Now the last few lines are:

    if (wfRunHooks('Event3', array(&$somestring))) {
        echo $somestring; # prints "Eggs, bananas, bacon and so on."
    }

Adding a reference to an array keeps its "reference-ness". Note that there's no
change to the (extension-located) hook function, just to the core code calling
conventions.

The above change has been implemented in HEAD; it needs to be ported to REL1_4.
(It was implemented and tested in REL1_4 originally, then moved to HEAD at the
request of vibber).
Comment 1 Brion Vibber 2005-04-21 10:38:00 UTC
This got done a while ago iirc. Closing.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links