From 0364e35e7d51d0cc31cccdc9c1067b277419ef27 Mon Sep 17 00:00:00 2001 From: "uwe.tews@googlemail.com" Date: Tue, 27 Mar 2012 17:07:32 +0000 Subject: [PATCH] - bugfix implement Smarty2's behaviour of variables assigned by reference in SmartyBC. {assign} will affect all references. (issue 88) --- change_log.txt | 2 ++ libs/sysplugins/smarty_internal_compile_assign.php | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/change_log.txt b/change_log.txt index ec0b1115..26f76818 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,8 @@ ===== trunk ===== 27.03.2012 - bugfix prefilter did run multiple times on inline subtemplates compiled into several main templates (Forum Topic 21325) +- bugfix implement Smarty2's behaviour of variables assigned by reference in SmartyBC. {assign} will affect all references. + (issue 88) 21.03.2012 - bugfix compileAllTemplates() and compileAllConfig() did not return the number of compiled files (Forum Topic 21286) diff --git a/libs/sysplugins/smarty_internal_compile_assign.php b/libs/sysplugins/smarty_internal_compile_assign.php index 40e46862..0ac3f68c 100644 --- a/libs/sysplugins/smarty_internal_compile_assign.php +++ b/libs/sysplugins/smarty_internal_compile_assign.php @@ -58,7 +58,14 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase { if (isset($parameter['smarty_internal_index'])) { $output = "createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];"; } else { - $output = "tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);"; + // implement Smarty2's behaviour of variables assigned by reference + if ($compiler->template->smarty instanceof SmartyBC) { + $output = "tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];"; + $output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache; \$_smarty_tpl->tpl_vars[$_attr[var]]->scope = $_scope;"; + $output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);"; + } else { + $output = "tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);"; + } } if ($_scope == Smarty::SCOPE_PARENT) { $output .= "\nif (\$_smarty_tpl->parent != null) \$_smarty_tpl->parent->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";