assign by reference
| From: | Bob Silva | Date: | Thu, 25 Jul 2002 04:10:04 +0000 |
| Subject: | assign by reference | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-223@lists.php.net to get a copy of this message | ||
Would be nice to use a reference so that changes to the variable can be made
during Smarty template processing.
In our case, we assign() our Application object to smarty when we
instantiate smarty. Many configuration changes
happen to the App object after the assignment before template processing.
Those changes cant be seen because
smarty stored a copy of the variable.
It would be nice to allow smarty to assign by reference in such instances.
Performance buffs would/should use this method regardless to reduce the
memory overhead of copying the variable. However, this would remove the
capability to use an array in the assignment, since you cant assign a
default value in the function definition for values passed by reference.
/*======================================================================*\
Function: assign_by_ref()
Purpose: assigns values to template variables using references
Parameters: $tpl_var - Name of the variable
$value - A reference to the variable contents
\*======================================================================*/
function assign_by_ref($tpl_var, &$value)
{
if ($tpl_var != '' && isset($value))
$this->_tpl_vars[$tpl_var] = &$value;
$this->_extract = true;
}