From: Marius Hoch Date: Tue, 23 Jan 2018 18:44:28 +0000 (-0800) Subject: ExtensionRegistry: Properly detect if a global is already set X-Git-Tag: 1.31.0-rc.0~820 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=cc433d1ff1dd9e196a911fcc9dd3748611b413ed;p=lhc%2Fweb%2Fwiklou.git ExtensionRegistry: Properly detect if a global is already set $foo = null; isset( $foo ); will yield false. Sometimes we want to explicitly set a config to null, but ExtensionRegistry is then overriding this variable with the default value. This is no consistent with the old workflow: require_once the extension and then override the setting with null. Bug: T128661 Change-Id: I0654c9369a596e84591fcaa9643703e6b4ccf57e --- diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index 6308461438..ae1ab58906 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -291,7 +291,7 @@ class ExtensionRegistry { // Optimistic: If the global is not set, or is an empty array, replace it entirely. // Will be O(1) performance. - if ( !isset( $GLOBALS[$key] ) || ( is_array( $GLOBALS[$key] ) && !$GLOBALS[$key] ) ) { + if ( !array_key_exists( $key, $GLOBALS ) || ( is_array( $GLOBALS[$key] ) && !$GLOBALS[$key] ) ) { $GLOBALS[$key] = $val; continue; } diff --git a/tests/phpunit/includes/registration/ExtensionRegistryTest.php b/tests/phpunit/includes/registration/ExtensionRegistryTest.php index 9b57e1c3d1..5916b4510b 100644 --- a/tests/phpunit/includes/registration/ExtensionRegistryTest.php +++ b/tests/phpunit/includes/registration/ExtensionRegistryTest.php @@ -287,6 +287,18 @@ class ExtensionRegistryTest extends MediaWikiTestCase { ], ], ], + [ + 'global is null before', + [ + 'NullGlobal' => null, + ], + [ + 'NullGlobal' => 'not-null' + ], + [ + 'NullGlobal' => null + ], + ], ]; } }