[TASK] Cleanup foreach() by using references
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Fri, 17 Jun 2011 19:53:52 +0000 (21:53 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 18 Jun 2011 14:35:05 +0000 (16:35 +0200)
Using references for foreach-values makes handling
easier in some cases.
Also added (according to php-documentation) unset()
after foreach() on the variable used for the reference.

Change-Id: I7137c50d49a3f7aa812b8cbd1c4098e481b8376f
Resolves: #27529
Reviewed-on: http://review.typo3.org/2791
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
14 files changed:
t3lib/class.t3lib_div.php
t3lib/class.t3lib_extmgm.php
t3lib/class.t3lib_iconworks.php
t3lib/class.t3lib_install.php
t3lib/class.t3lib_parsehtml.php
t3lib/class.t3lib_stdgraphic.php
t3lib/class.t3lib_tceforms_inline.php
t3lib/class.t3lib_tcemain.php
t3lib/class.t3lib_timetrack.php
t3lib/class.t3lib_tstemplate.php
typo3/class.browse_links.php
typo3/sysext/beuser/mod/index.php
typo3/sysext/cms/tslib/class.tslib_content.php
typo3/sysext/css_styled_content/pi1/class.tx_cssstyledcontent_pi1.php

index dadaa2f..caae0b3 100644 (file)
@@ -1905,8 +1905,8 @@ final class t3lib_div {
                        } else {
                                $value = addslashes($value);
                        }
-                       unset($value);
                }
+               unset($value);
                reset($theArray);
        }
 
@@ -1927,8 +1927,8 @@ final class t3lib_div {
                        } else {
                                $value = stripslashes($value);
                        }
-                       unset($value);
                }
+               unset($value);
                reset($theArray);
        }
 
@@ -3279,6 +3279,7 @@ final class t3lib_div {
                                return 'ERROR: One or more of the files was NOT prefixed with the prefix-path!';
                        }
                }
+               unset($absFileRef);
                return $fileArr;
        }
 
@@ -4469,12 +4470,14 @@ final class t3lib_div {
                                        foreach ($LOCAL_LANG['default'] as &$labelValue) {
                                                $labelValue = $csConvObj->conv($labelValue, 'iso-8859-1', $targetCharset);
                                        }
+                                       unset($labelValue);
                                }
 
                                if ($langKey != 'default' && is_array($LOCAL_LANG[$langKey]) && $sourceCharset != $targetCharset) {
                                        foreach ($LOCAL_LANG[$langKey] as &$labelValue) {
                                                $labelValue = $csConvObj->conv($labelValue, $sourceCharset, $targetCharset);
                                        }
+                                       unset($labelValue);
                                }
 
                                        // Cache the content now:
@@ -4577,9 +4580,10 @@ final class t3lib_div {
 
                                                // Checking if charset should be converted.
                                        if (is_array($LOCAL_LANG[$langKey]) && $targetCharset != 'utf-8') {
-                                               foreach ($LOCAL_LANG[$langKey] as $labelKey => $labelValue) {
-                                                       $LOCAL_LANG[$langKey][$labelKey] = $csConvObj->utf8_decode($labelValue, $targetCharset);
+                                               foreach ($LOCAL_LANG[$langKey] as &$labelValue) {
+                                                       $labelValue = $csConvObj->utf8_decode($labelValue, $targetCharset);
                                                }
+                                               unset($labelValue);
                                        }
                                }
 
@@ -4628,9 +4632,10 @@ final class t3lib_div {
 
                                                        // Checking if charset should be converted.
                                                if (is_array($LOCAL_LANG[$langKey]) && $targetCharset != 'utf-8') {
-                                                       foreach ($LOCAL_LANG[$langKey] as $labelKey => $labelValue) {
-                                                               $LOCAL_LANG[$langKey][$labelKey] = $csConvObj->utf8_decode($labelValue, $targetCharset);
+                                                       foreach ($LOCAL_LANG[$langKey] as &$labelValue) {
+                                                               $labelValue = $csConvObj->utf8_decode($labelValue, $targetCharset);
                                                        }
+                                                       unset($labelValue);
                                                }
 
                                                        // Cache the content now:
@@ -4653,13 +4658,15 @@ final class t3lib_div {
                        }
 
                                // Convert the $LOCAL_LANG array to XLIFF structure
-                       foreach ($LOCAL_LANG as $languageKey => $keysLabels) {
-                               foreach ($keysLabels as $key => $label) {
-                                       $LOCAL_LANG[$languageKey][$key] = array(0 => array(
+                       foreach ($LOCAL_LANG as &$keysLabels) {
+                               foreach ($keysLabels as &$label) {
+                                       $label = array(0 => array(
                                                'target' => $label,
                                        ));
                                }
+                               unset($label);
                        }
+                       unset($keysLabels);
 
                        return $LOCAL_LANG;
                }
@@ -5464,6 +5471,7 @@ final class t3lib_div {
                                        $v = $newURL . substr($v, strlen($newParts[0]));
                                }
                        }
+                       unset($v);
                        $message = implode('', $urlSplit);
                }
 
@@ -5848,6 +5856,7 @@ final class t3lib_div {
                                $val = preg_replace('/(^\'|\'$)/', '', $val);
 
                        }
+                       unset($val);
                }
                        // return reindexed array
                return array_values($paramsArr);
@@ -5920,4 +5929,4 @@ final class t3lib_div {
        }
 }
 
-?>
+?>
\ No newline at end of file
index 2bc12c8..565c654 100644 (file)
@@ -354,6 +354,7 @@ final class t3lib_extMgm {
                                        }
                                }
                        }
+                       unset($typeDetails);
                }
        }
 
index 3fb4e2d..a561f11 100644 (file)
@@ -867,9 +867,10 @@ final class t3lib_iconWorks {
                                        );
                                }
                        } else {
-                               foreach ($recordType AS $key => $type) {
-                                       $recordType[$key] = 'tcarecords-' . $table . '-' . $type;
+                               foreach ($recordType as &$type) {
+                                       $type = 'tcarecords-' . $table . '-' . $type;
                                }
+                               unset($type);
                                $recordType[0] = 'tcarecords-' . $table . '-default';
                        }
                } else {
index efa9ac4..9df6d94 100644 (file)
@@ -1093,6 +1093,7 @@ class t3lib_install {
                foreach ($whichTables as $key => &$value) {
                        $value = $key;
                }
+               unset($value);
                return $whichTables;
        }
 
index 563910e..f05e80f 100644 (file)
@@ -1068,11 +1068,12 @@ class t3lib_parsehtml {
                $prefix = isset($alternatives['style']) ? $alternatives['style'] : $main_prefix;
                if (strlen($prefix)) {
                        $parts = $this->splitIntoBlock('style', $content);
-                       foreach ($parts as $k => $v) {
+                       foreach ($parts as $k => &$part) {
                                if ($k % 2) {
-                                       $parts[$k] = preg_replace('/(url[[:space:]]*\([[:space:]]*["\']?)([^"\')]*)(["\']?[[:space:]]*\))/i', '\1' . $prefix . '\2' . $suffix . '\3', $parts[$k]);
+                                       $part = preg_replace('/(url[[:space:]]*\([[:space:]]*["\']?)([^"\')]*)(["\']?[[:space:]]*\))/i', '\1' . $prefix . '\2' . $suffix . '\3', $part);
                                }
                        }
+                       unset($part);
                        $content = implode('', $parts);
                }
 
@@ -1229,11 +1230,12 @@ class t3lib_parsehtml {
                if (is_array($str)) {
                        if (!$cacheKey || !isset($this->caseShift_cache[$cacheKey])) {
                                reset($str);
-                               foreach ($str as $k => $v) {
+                               foreach ($str as &$v) {
                                        if (!$flag) {
-                                               $str[$k] = strtoupper($v);
+                                               $v = strtoupper($v);
                                        }
                                }
+                               unset($v);
                                if ($cacheKey) {
                                        $this->caseShift_cache[$cacheKey] = $str;
                                }
@@ -1299,9 +1301,10 @@ class t3lib_parsehtml {
        function indentLines($content, $number = 1, $indentChar = TAB) {
                $preTab = str_pad('', $number * strlen($indentChar), $indentChar);
                $lines = explode(LF, str_replace(CR, '', $content));
-               foreach ($lines as $k => $v) {
-                       $lines[$k] = $preTab . $v;
+               foreach ($lines as &$line) {
+                       $line = $preTab . $line;
                }
+               unset($line);
                return implode(LF, $lines);
        }
 
index fe161d5..66a9962 100644 (file)
@@ -768,6 +768,7 @@ class t3lib_stdGraphic {
                                foreach ($theBBoxInfo as &$value) {
                                        $value = ceil($value / $sF);
                                }
+                               unset($value);
                        }
                }
                return array($x, $y, $theBBoxInfo);
index 246abfe..fe3bee0 100644 (file)
@@ -1499,6 +1499,7 @@ class t3lib_TCEforms_inline {
                        $parts = explode('|', $value, 2);
                        $value = $parts[0];
                }
+               unset($value);
                return $itemArray;
        }
 
index 01c9241..6075374 100644 (file)
@@ -1839,6 +1839,7 @@ class t3lib_TCEmain {
                                                        $theFile = substr($theFile, strlen(PATH_site));
                                                }
                                        }
+                                       unset($theFile);
                                }
                        }
                }
@@ -2296,6 +2297,7 @@ class t3lib_TCEmain {
                                str_replace('|', '', rawurldecode($temp[0]))
                        );
                }
+               unset($newVal);
                return $valueArray;
        }
 
index 6cb40c6..53dcc48 100644 (file)
@@ -281,6 +281,7 @@ class t3lib_timeTrack {
                                $data['key'] = implode($data['stackPointer'] ? '.' : '/', end($data['tsStack']));
                        }
                }
+               unset($data);
 
                        // Create hierarchical array of keys pointing to the stack
                $arr = array();
index 521f709..4ef8a88 100644 (file)
@@ -948,18 +948,22 @@ class t3lib_TStemplate {
                        $files = array_merge($files, $includeData['files']);
                        $value = $includeData['typoscript'];
                }
+               unset($value);
 
                foreach ($this->config as &$value) {
                        $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE);
                        $files = array_merge($files, $includeData['files']);
                        $value = $includeData['typoscript'];
                }
+               unset($value);
 
                foreach ($this->editorcfg as &$value) {
                        $includeData = t3lib_TSparser::checkIncludeLines($value, 1, TRUE);
                        $files = array_merge($files, $includeData['files']);
                        $value = $includeData['typoscript'];
                }
+               unset($value);
+
                if (count($files)) {
                        $files = array_unique($files);
                        foreach ($files as $file) {
@@ -1601,4 +1605,4 @@ if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLA
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']);
 }
 
-?>
+?>
\ No newline at end of file
index 9a050c7..e51842d 100644 (file)
@@ -2883,6 +2883,7 @@ class browse_links {
                                foreach ($fieldChangeFunctions as &$value) {
                                        $value = str_replace($originalName, $cleanedName, $value);
                                }
+                               unset($value);
                        }
 
                        $result = ($this->P['fieldChangeFuncHash'] === t3lib_div::hmac(serialize($fieldChangeFunctions)));
index 4f6aefd..e67e3e7 100755 (executable)
@@ -642,6 +642,7 @@ class local_beUserAuth extends t3lib_beUserAuth {
                                                foreach ($pageTypes as &$vv) {
                                                        $vv = $GLOBALS['LANG']->sL(t3lib_BEfunc::getLabelFromItemlist('pages','doktype',$vv));
                                                }
+                                               unset($vv);
                                                $out[$k] = implode('<br />',$pageTypes);
                                        break;
                                        case 'tables_select':
@@ -652,6 +653,7 @@ class local_beUserAuth extends t3lib_beUserAuth {
                                                                $vv = '<span class="nobr">'.t3lib_iconWorks::getSpriteIconForRecord($vv,array()).$GLOBALS['LANG']->sL($GLOBALS['TCA'][$vv]['ctrl']['title']).'</span>';
                                                        }
                                                }
+                                               unset($vv);
                                                $out[$k] = implode('<br />',$tables);
                                        break;
                                        case 'non_exclude_fields':
@@ -1033,6 +1035,7 @@ class local_beUserAuth extends t3lib_beUserAuth {
                                $this->ext_ksortArrayRecursive($v);
                        }
                }
+               unset($v);
        }
 
        /**
index 9c9fdae..933f455 100644 (file)
@@ -7437,6 +7437,7 @@ class tslib_cObj {
                                foreach ($queryParts as $queryPartKey => &$queryPartValue) {
                                        $queryPartValue = str_replace('###' . $marker . '###', $markerValue, $queryPartValue);
                                }
+                               unset($queryPartValue);
                        }
 
                        $query = $GLOBALS['TYPO3_DB']->SELECTquery(
index 5737679..a5f2d4f 100755 (executable)
@@ -103,6 +103,7 @@ class tx_cssstyledcontent_pi1 extends tslib_pibase {
                        foreach($lines as &$val)        {
                                $val = '<li>'.$this->cObj->stdWrap($val,$conf['innerStdWrap.']).'</li>';
                        }
+                       unset($val);
 
                                // Set header type:
                        $type = intval($this->cObj->data['layout']);