This is the same problem I encountered back in December when I tried using the hooks to insert extra information into the template's context
http://mail.wikipedia.org/pipermail/wikitech-l/2004-December/026533.html
In that email, I suggested using a named array rather than a simple array to pass the parameters. Do you think this might provide more clarity?
Also, what about including this actual setupTemplate processing hook that I proposed?
/Jonah
On Sat, 2005-03-12 at 09:46 -0500, Evan Prodromou wrote:
--=-HwYMtKXwosVZ95m4MJOb Content-Type: text/plain Content-Transfer-Encoding: quoted-printable
I made a late checkin on the 1.4 branch today.
The problem was 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, was using PHP's variable-argument syntax so you could 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'][] =3D 'MyEvent3Handler'; # ... function MyEvent3Handler(&$str) { $str .=3D " and so on."; return true;
} # ... $somestring =3D "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".
I wanted to make sure that the hooks technology was at least worth experimenting with in the 1.4 branch, and that the interface (from both sides) was relatively stable. Hooks need to be able to modify their parameters to be useful, so I made these changes.
I've done pretty extensive testing of all the points in 1.4 where wfRunHooks() is called, and it seems to be stable.
~Evan
--=20 Evan Prodromou evan@bad.dynu.ca
--=-HwYMtKXwosVZ95m4MJOb-- _______________________________________________ Wikitech-l mailing list Wikitech-l@wikimedia.org http://mail.wikipedia.org/mailman/listinfo/wikitech-l