diff --git a/change_log.txt b/change_log.txt index c68d2dfe..8243e478 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@ ===== 3.1.31-dev ===== (xx.xx.xx) 09.09.2016 - bugfix/optimization {foreach} did not execute the {foreachelse} when iterating empty objects https://github.com/smarty-php/smarty/pull/287 + - bugfix {foreach} must keep the @properties when restoring a saved $item variable as the properties might be used outside {foreach} https://github.com/smarty-php/smarty/issues/267 08.09.2016 - bugfix implement wrapper for removed method getConfigVariable() https://github.com/smarty-php/smarty/issues/286 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 6e159b79..09bfd413 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.31-dev/14'; + const SMARTY_VERSION = '3.1.31-dev/15'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_runtime_foreach.php b/libs/sysplugins/smarty_internal_runtime_foreach.php index ed3b5f54..812a8bd3 100644 --- a/libs/sysplugins/smarty_internal_runtime_foreach.php +++ b/libs/sysplugins/smarty_internal_runtime_foreach.php @@ -50,7 +50,7 @@ class Smarty_Internal_Runtime_Foreach $total = empty($from) ? 0 : (($needTotal || isset($properties[ 'total' ])) ? count($from) : 1); } if (isset($tpl->tpl_vars[ $item ])) { - $saveVars[ $item ] = $tpl->tpl_vars[ $item ]; + $saveVars[ 'item' ] = array($item, $tpl->tpl_vars[ $item ]); } $tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache); if ($total === 0) { @@ -58,7 +58,7 @@ class Smarty_Internal_Runtime_Foreach } else { if ($key) { if (isset($tpl->tpl_vars[ $key ])) { - $saveVars[ $key ] = $tpl->tpl_vars[ $key ]; + $saveVars[ 'key' ] = array($key, $tpl->tpl_vars[ $key ]); } $tpl->tpl_vars[ $key ] = new Smarty_Variable(null, $tpl->isRenderingCache); } @@ -69,7 +69,7 @@ class Smarty_Internal_Runtime_Foreach if ($name) { $namedVar = "__smarty_foreach_{$name}"; if (isset($tpl->tpl_vars[ $namedVar ])) { - $saveVars[ $namedVar ] = $tpl->tpl_vars[ $namedVar ]; + $saveVars[ 'named' ] = array($namedVar, $tpl->tpl_vars[ $namedVar ]); } $namedProp = array(); if (isset($properties[ 'total' ])) { @@ -97,8 +97,16 @@ class Smarty_Internal_Runtime_Foreach */ public function restore(Smarty_Internal_Template $tpl) { - foreach (array_pop($this->stack) as $k => $v) { - $tpl->tpl_vars[ $k ] = $v; + $saveVars = array_pop($this->stack); + if (isset($saveVars['item'])) { + $item = &$saveVars['item']; + $tpl->tpl_vars[ $item[0] ]->value = $item[1]->value; + } + if (isset($saveVars['key'])) { + $tpl->tpl_vars[ $saveVars['key'][0] ] = $saveVars['key'][1]; + } + if (isset($saveVars['named'])) { + $tpl->tpl_vars[ $saveVars['named'][0] ] = $saveVars['named'][1]; } }