Re: [SMARTY] Assign a reference to a variable
| From: | Monte Ohrt | Date: | Fri, 02 Aug 2002 15:45:24 +0000 |
| Subject: | Re: [SMARTY] Assign a reference to a variable | ||
| References: | 1 | Groups: | php.smarty.dev php.smarty.general |
| Request: | Send a blank email to php-smarty-dev+get-232@lists.php.net to get a copy of this message | ||
Well it seems that this idea doesn't work as planned. We'll have to make separate assign_by_ref() and append_by_ref() functions.
Basically, you can't pass a static value by reference, so it would break assign().
Once PHP 5.0 comes out, assign() will work by reference anyways.
Monte
David M. Patterson wrote:
Personally, I think this is a great idea. Storing references would be more efficient and it solves the problem mentioned in Hendy Irawan's original post; modifying a variable after assigning it to Smarty. Just my 2cents. D.-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.-----Original Message----- From: Monte Ohrt [mailto:monte@ispi.net] Sent: Friday, August 02, 2002 7:09 AM To: Hendy Irawan Cc: smarty-general@lists.php.net Subject: Re: [SMARTY] Assign a reference to a variable This has come up before, and I like the idea of assigning by reference. It would be noticably more efficient, which is always a good thing. We do have a backward compatability issue, but that is probably a rare case. How about this: We change the default behavior of assign() to assign variables by reference. We add a new class variable $assign_by_ref which defaults to true. If you really want copies of the data assigned (backward compatible), you can set this flag to false. append() would also respect this flag. Also realize if we assign by reference, Smarty would no longer loop through an assigned array and test that keys/values are not empty. They will just get assigned as-is. I don't recall why Smarty does this anyways... you probably don't want to assign empty keys/vals, but should that be Smarty's responsibility? PHP 5.0 will do all of this implicitly, but that is a ways off. Thoughts? Monte Hendy Irawan wrote:smarty-general, I want to do something like: $smarty->assign('myobj', $myobj); Where $myobj is an object. However, later I want to change $myobj (before displaying the template) but the changes are not visible. Doing: $smarty->assign('myobj', &$myobj); seems to have no effect. Is there a way to solve this problem? Assigning these variables exactly before it's displayed is not a solution. Salam hangat, Hendy Irawan - www.GaulDong.NET Kantor: (021) 5260467 [SoftVation] Kos: (021) 5261839 [kamar 3]-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc. -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php