Re[4]: [SMARTY-DEV] mixing of asign() and assign_by_ref() overwrites external vars

From: Date: Tue, 08 Jun 2004 00:23:30 +0000
Subject: Re[4]: [SMARTY-DEV] mixing of asign() and assign_by_ref() overwrites external vars
References: 1 2  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2410@lists.php.net to get a copy of this message
B> 1) I don't agree that it is unsuspected; it follows the PHP4 paradigm. Do, $smarty->assign("a", "b") has EQUAL paradigm as PHP's $a="b". Agree? Do you plan exactly this while developing assign() function? Is it documented? B> 2) I don't agree that it is transparent: messju already pointed out the B> problem with deprecated pass-by-reference. It is not a problem. You may not use deprecated syntax at all. B> 3) I agree with Monte's sentiment: don't fix what isn't broken. In my B> last post, I show the standard work-around for getting the behaviour B> that was desired in the case originally given. It uses an existing API B> call which merely wraps what you would have to do with straight PHP: B> use unset(). Oh. B> 4) You are overloading the meaning of assign() to allow B> pass-by-reference whereas the Smarty API already decided long ago to B> break that into a different API call, namely assign_by_ref(). I think B> it is more confusing when you have two methods to do ostensibly the B> same thing. But you surely can not modify API nor use deprecated syntax. function assign($tpl_var, $val = null) { // First copy - always! $value = $val; // Then - assign by ref, to avoid unexpected (?) behavour. 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; } } So, now API is not touched, deprecated & call works as without &, but assign() after assign_by_ref() does not modify source variable. P.S. It is now question of principle, of course, not practical. -- Best regards, Dmitry Koteroff.

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