In the past, $wgHooks could be manipulated to register and unregister hook handlers dynamically. This greatly complicate the logic in HookContainer. Code that needs to register hooks dynamically should use HookContainer::register or HookContainer::scopedRegister instead.
Extensions in WMF production that set $wgHooks conditionally:
-
CentralAuthCentralAuth::onReegistration is a registration callback, so it can safely modify $wgHooks. -
CentralNoticeCentralNoticeHooks::onReegistration is a registration callback, so it can safely modify $wgHooks.
Other extensions that may still need fixing, but write accefss to $wgHooks has been emitting deprecation warnings since MW 1.40.