[BUGFIX] L10n PHP parser stores NULL for unknown key
authorXavier Perseguers <xavier@typo3.org>
Wed, 5 Sep 2012 07:06:40 +0000 (09:06 +0200)
committerXavier Perseguers <xavier@typo3.org>
Sun, 9 Sep 2012 19:59:30 +0000 (21:59 +0200)
The PHP parser caches NULL instead of an array when the Backend
language is not available for a given extension using PHP array
localization files (e.g., tscobj with German "de").

This leads to PHP warning when reading the labels as NULL cannot
be used in a foreach statement.

Change-Id: I1678674ecfba71e04c9c13aed44dd7f0aa574cbc
Fixes: #40643
Releases: 6.0, 4.7, 4.6
Reviewed-on: http://review.typo3.org/14360
Reviewed-by: Philipp Gampe
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
typo3/sysext/core/Classes/Localization/Parser/LocallangArrayParser.php

index 629444d..a145807 100644 (file)
@@ -158,7 +158,11 @@ class LocallangArrayParser implements \TYPO3\CMS\Core\Localization\Parser\Locali
                        unset($labelValue);
                }
                // Cache the content now:
-               $serContent = array('origFile' => $this->hashSource, 'LOCAL_LANG' => array('default' => $LOCAL_LANG['default'], $languageKey => $LOCAL_LANG[$languageKey]));
+               if (isset($LOCAL_LANG[$languageKey])) {
+                       $serContent = array('origFile' => $this->hashSource, 'LOCAL_LANG' => array('default' => $LOCAL_LANG['default'], $languageKey => $LOCAL_LANG[$languageKey]));
+               } else {
+                       $serContent = array('origFile' => $this->hashSource, 'LOCAL_LANG' => array('default' => $LOCAL_LANG['default']));
+               }
                $res = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir($this->cacheFileName, serialize($serContent));
                if ($res) {
                        throw new \RuntimeException('TYPO3 Fatal Error: "' . $res, 1308898501);