Re[2]: mixing of asign() and assign_by_ref() overwrites external vars

From: Date: Fri, 04 Jun 2004 15:26:13 +0000
Subject: Re[2]: mixing of asign() and assign_by_ref() overwrites external vars
References: 1 2 3  Groups: php.smarty.dev php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2392@lists.php.net to get a copy of this message
Seems function assign($tpl_var, $value = null) { if (is_array($tpl_var)){ foreach ($tpl_var as $key => $val) { if ($key != '') { $this->_tpl_vars[$key] =& $val; } } } else { if ($tpl_var != '') $this->_tpl_vars[$tpl_var] =& $value; } } in Smarty.class.php, lines near 580, will solve the issue (I have added two =& instead of =). And, in addition, it allows to use more intuitive $smarty->assign($key, &$value); instead of $smarty->assign_by_ref($key, $value); Command $smarty->assign($key, $value); works as usual, with no side-effects. SM> Boots schrieb: >>>>>$testvar = true; >>>>>$smarty = new Smarty; >>>>> >>>>>$smarty->assign_by_ref('testvar', $testvar); >>>>> >>>>>// bug? >>>>>var_dump($testvar); // prints: (bool) true >>>>>$smarty->assign('testvar', false); >>>>>var_dump($testvar); // prints: (bool) false >>>> >>>>What do you think should happen? You are changing a by-reference >>>>value >>> >>>i expect if i use appand() that the reference is unset by smarty, >>>cause >>>i dont think that any body wants to set an external var this way! >> >> I suspect you don't really want to use append_by_ref then. SM> of course, i could, and this all is not really a problem for me, SM> its just that this is not what i expected! SM> if i assign a var by reference to smarty, than cause i want to make SM> changes to this var after i append it to smarty, or to save resources SM> but never to overwrite this extern var by a call to append() SM> if others think this is not a bug ... not my problem! as i said i have SM> no problem with this behavior SM> p.s. sorry for my english -- Best regards, Dmitry Koteroff.

« previous php.smarty.dev (#2392) next »