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

Dmitry Koteroff <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
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.

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.