There's a bug with {assign} combined with {foreach}

From: Date: Tue, 01 Oct 2002 22:48:26 +0000
Subject: There's a bug with {assign} combined with {foreach}
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6061@lists.php.net to get a copy of this message
Hello! There's a strange behaviour when you use {assign} in combination with a {foreach} loop. Example: bar is an array of the following format: $smarty->assign('bar', array('one', 'two', 'three')); {foreach item=foo from=$bar} {assign var=tmp value="foo: $foo"} {$tmp}<br> {/foreach} This will output: foo: foo: one foo: two I had a look at the compiled template: <?php /* Smarty version 2.2.0, created on 2002-10-02 00:41:49 compiled from test.ihtml */ ?> <?php $this->_load_plugins(array( array('function', 'assign', 'test.ihtml', 2, false),)); ?><?php if (count((array)$this->_tpl_vars['bar'])): foreach ((array)$this->_tpl_vars['bar'] as $this->_tpl_vars['foo']): ?> <?php $this->_plugins['function']['assign'][0](array('var' => "tmp",'value' => "foo: $foo"), $this); if($this->_extract) { extract($this->_tpl_vars); $this->_extract=false; } ?> <?php echo $this->_tpl_vars['tmp']; ?> <br> <?php endforeach; endif; ?> The problem is that it uses $smarty->_tpl_vars['foo'] in the foreach-statement but then uses $foo in the assign. I changed $foo to {$this->_tpl_vars['foo']} and then it worked just fine. So, is this a bug in the smarty compile engine and is it possible to fix? Sincerely Nichlas

« previous php.smarty.general (#6061) next »