From: Kunal Mehta Date: Mon, 15 Oct 2018 07:17:38 +0000 (-0700) Subject: LocalisationCache: Avoid use of compact() X-Git-Tag: 1.34.0-rc.0~3768^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22auteur_infos%22%2C%20%22id_auteur=%24id%22%29%20.%20%22?a=commitdiff_plain;ds=sidebyside;h=d0463178dfa09b79b3a08fee939da1beed030824;hp=6cb3fa392f5772f9e5e7b4b4769da1ba4cfda891;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/includes/cache/localisation/LocalisationCache.php b/includes/cache/localisation/LocalisationCache.php index d0381cf04d..f20637a420 100644 --- a/includes/cache/localisation/LocalisationCache.php +++ b/includes/cache/localisation/LocalisationCache.php @@ -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" ); }