From 18fcb2bf29eca1ad0c15aafaa3b4bf4b1c8a3355 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 15 Oct 2018 00:17:38 -0700 Subject: [PATCH] LocalisationCache: Avoid use of compact() 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 (cherry picked from commit d0463178dfa09b79b3a08fee939da1beed030824) --- RELEASE-NOTES-1.31 | 2 ++ includes/cache/localisation/LocalisationCache.php | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.31 b/RELEASE-NOTES-1.31 index b4f95ca349..81854abf03 100644 --- a/RELEASE-NOTES-1.31 +++ b/RELEASE-NOTES-1.31 @@ -11,6 +11,8 @@ THIS IS NOT A RELEASE YET * (T109121) Remove deprecated pear/mail_mime-decode from composer suggested libraries. * (T200595) Fix PHP 7.3 warnings of using "continue" in some scenarios instead of "break". +* (T206979) Fix PHP 7.3 warnings of using "compact()" when some variables may + not be set. == MediaWiki 1.31.1 == diff --git a/includes/cache/localisation/LocalisationCache.php b/includes/cache/localisation/LocalisationCache.php index dd9e8e194a..e7b955489d 100644 --- a/includes/cache/localisation/LocalisationCache.php +++ b/includes/cache/localisation/LocalisationCache.php @@ -527,10 +527,20 @@ class LocalisationCache { ini_set( 'apc.cache_by_default', $_apcEnabled ); Wikimedia\restoreWarnings(); + $data = []; if ( $_fileType == 'core' || $_fileType == 'extension' ) { - $data = compact( self::$allKeys ); + 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" ); } -- 2.20.1