From c7b8bc69e49b40797f7cda469699dcf47740dba5 Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Sun, 28 Jul 2013 01:22:51 -0700 Subject: [PATCH] $wgHooks: add closure docs & admonition to register handlers early This patch takes Tim's advice to amend the doc block for $wgHooks with an admonition to register hook handlers early. (This was after it was determined that late registration of a CanonicalNamespace handler was responsible for bug 45031). Since I was already here, I also documented the use of closures with $wgHooks, fulfilling a @TODO. Change-Id: Id16148dbfbcc89e0365860e078e089ae541ba08f --- includes/DefaultSettings.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 86b08498fd..c638f5230c 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5491,17 +5491,24 @@ $wgAuth = null; * @endcode * - A function with some data: * @code - * $wgHooks['event_name'][] = array($function, $data); + * $wgHooks['event_name'][] = array( $function, $data ); * @endcode * - A an object method: * @code - * $wgHooks['event_name'][] = array($object, 'method'); + * $wgHooks['event_name'][] = array( $object, 'method' ); + * @endcode + * - A closure: + * @code + * $wgHooks['event_name'][] = function ( $hookParam ) { + * // Handler code goes here. + * }; * @endcode * * @warning You should always append to an event array or you will end up * deleting a previous registered hook. * - * @todo Does it support PHP closures? + * @warning Hook handlers should be registered at file scope. Registering + * handlers after file scope can lead to unexpected results due to caching. */ $wgHooks = array(); -- 2.20.1