mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- bugfix assigning a variable in if condition by function like {if $value = array_shift($array)} the function got called twice https://github.com/smarty-php/smarty/issues/291
This commit is contained in:
@@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.31-dev/21';
|
||||
const SMARTY_VERSION = '3.1.31-dev/22';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -48,20 +48,20 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
// create nocache var to make it know for further compiling
|
||||
$compiler->setNocacheInVariable($var);
|
||||
}
|
||||
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
||||
$prefixVar = $compiler->getNewPrefixVariable();
|
||||
$_output = "<?php {$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ";?>\n";
|
||||
$assignAttr = array();
|
||||
$assignAttr[][ 'value' ] = $parameter[ 'if condition' ][ 'value' ];
|
||||
$assignAttr[][ 'value' ] = "{$prefixVar}";
|
||||
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||
$_output = $assignCompiler->compile($assignAttr, $compiler,
|
||||
$_output .= $assignCompiler->compile($assignAttr, $compiler,
|
||||
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
|
||||
} else {
|
||||
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
|
||||
$_output = $assignCompiler->compile($assignAttr, $compiler, array());
|
||||
$_output .= $assignCompiler->compile($assignAttr, $compiler, array());
|
||||
}
|
||||
$_output .= "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
|
||||
(isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
|
||||
$parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] : '') . ") {?>";
|
||||
$_output .= "<?php if ({$prefixVar}) {?>";
|
||||
return $_output;
|
||||
} else {
|
||||
return "<?php if ({$parameter['if condition']}) {?>";
|
||||
@@ -137,16 +137,18 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
// create nocache var to make it know for further compiling
|
||||
$compiler->setNocacheInVariable($var);
|
||||
}
|
||||
$prefixVar = $compiler->getNewPrefixVariable();
|
||||
$assignCode = "<?php {$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ";?>\n";
|
||||
$assignCompiler = new Smarty_Internal_Compile_Assign();
|
||||
$assignAttr = array();
|
||||
$assignAttr[][ 'value' ] = $parameter[ 'if condition' ][ 'value' ];
|
||||
$assignAttr[][ 'value' ] = "{$prefixVar}";
|
||||
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
|
||||
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
|
||||
$assignCode = $assignCompiler->compile($assignAttr, $compiler,
|
||||
$assignCode .= $assignCompiler->compile($assignAttr, $compiler,
|
||||
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
|
||||
} else {
|
||||
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
|
||||
$assignCode = $assignCompiler->compile($assignAttr, $compiler, array());
|
||||
$assignCode .= $assignCompiler->compile($assignAttr, $compiler, array());
|
||||
}
|
||||
} else {
|
||||
$condition_by_assign = false;
|
||||
@@ -157,10 +159,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
if ($condition_by_assign) {
|
||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
$_output = $compiler->appendCode("<?php } else {\n?>", $assignCode);
|
||||
return $compiler->appendCode($_output, "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
|
||||
(isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
|
||||
$parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] :
|
||||
'') . ") {?>");
|
||||
return $compiler->appendCode($_output, "<?php if ({$prefixVar}) {?>");
|
||||
} else {
|
||||
$this->openTag($compiler, 'elseif', array($nesting, $compiler->tag_nocache));
|
||||
return "<?php } elseif ({$parameter['if condition']}) {?>";
|
||||
@@ -170,10 +169,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
if ($condition_by_assign) {
|
||||
$_output = $compiler->appendCode($_output, $assignCode);
|
||||
return $compiler->appendCode($_output, "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
|
||||
(isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
|
||||
$parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] :
|
||||
'') . ") {?>");
|
||||
return $compiler->appendCode($_output, "<?php if ({$prefixVar}) {?>");
|
||||
} else {
|
||||
return $compiler->appendCode($_output, "<?php if ({$parameter['if condition']}) {?>");
|
||||
}
|
||||
|
Reference in New Issue
Block a user