Re: [SMARTY] assign_by_ref() and append_by_ref()
| From: | Ferdinand Beyer | Date: | Fri, 02 Aug 2002 19:58:17 +0000 |
| Subject: | Re: [SMARTY] assign_by_ref() and append_by_ref() | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5555@lists.php.net to get a copy of this message | ||
On 2 Aug 2002 at 13:22, Monte Ohrt wrote:
> These two functions have been committed to CVS. Please try them and see
> how they work, or if they were done right.
>
> $smarty->assign_by_ref('foo',$my_array);
>
> The first parameter is not optional, it must have a value. The second
> paramater gets passed by reference so it must be a variable, not a literal.
>
> $smarty->append_by_ref('foo', $my_array);
>
> Same goes for this one. I'm not sure if append_by_ref is correct because
> benchmarks don't show anything different, but it seems to work OK.
>
> Monte
I don't understand the need of an assign_by_ref() method. Didn't you
read by post?
You can easily change assign so that it is able to allow both copies
and references. Let me demonstrate this with a general example:
class Example
{
var $myvar;
function assign($value)
{
$this->myvar = &$value;
}
}
$example = new Example();
// Pass a reference
$example->assign(&$ref);
// Pass a copy
$example->assign($copy);
// Pass a copy
$example->assign("This is a copied string.");
So whether assign() saves references or copies is controlled by
whether it is called with '&' or not - whether the value is passed by
reference or not.
IMO this is the most ellegant way to do it; assign_by_ref() is
unnecessary, ugly and confusing.
--
Ferdinand Beyer
<fbeyer@clickhand.de>