LocalisationCache: Avoid use of compact()
authorKunal Mehta <legoktm@member.fsf.org>
Mon, 15 Oct 2018 07:17:38 +0000 (00:17 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Mon, 15 Oct 2018 20:35:30 +0000 (13:35 -0700)
In PHP 7.3, compact() now raises notices if the variable is undefined, which
is something that we expect. So we can check whether the key exists instead
of bothering with compat() and suppressing warnings.

Bug: T206979
Change-Id: I612049db4debd850a2e6d10bc631d31aa17be898

includes/cache/localisation/LocalisationCache.php

index d0381cf..f20637a 100644 (file)
@@ -525,15 +525,20 @@ class LocalisationCache {
                ini_set( 'apc.cache_by_default', $_apcEnabled );
                Wikimedia\restoreWarnings();
 
+               $data = [];
                if ( $_fileType == 'core' || $_fileType == 'extension' ) {
-
-                       // Lnguage files aren't required to contain all the possible variables, so suppress warnings
-                       // when variables don't exist in tests
-                       Wikimedia\suppressWarnings();
-                       $data = compact( self::$allKeys );
-                       Wikimedia\restoreWarnings();
+                       foreach ( self::$allKeys as $key ) {
+                               // Not all keys are set in language files, so
+                               // check they exist first
+                               if ( isset( $$key ) ) {
+                                       $data[$key] = $$key;
+                               }
+                       }
                } elseif ( $_fileType == 'aliases' ) {
-                       $data = compact( 'aliases' );
+                       if ( isset( $aliases ) ) {
+                               /** @suppress PhanUndeclaredVariable */
+                               $data['aliases'] = $aliases;
+                       }
                } else {
                        throw new MWException( __METHOD__ . ": Invalid file type: $_fileType" );
                }