<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>assign_by_ref()</title> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Smarty Manual"> <link rel="up" href="api.functions.html" title="Chapter 13. Smarty Class Methods()"> <link rel="prev" href="api.assign.html" title="assign()"> <link rel="next" href="api.clear.all.assign.html" title="clear_all_assign()"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">assign_by_ref()</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="api.assign.html">Prev</a> </td> <th width="60%" align="center">Chapter 13. Smarty Class Methods()</th> <td width="20%" align="right"> <a accesskey="n" href="api.clear.all.assign.html">Next</a> </td> </tr> </table> <hr> </div> <div class="refentry" title="assign_by_ref()"> <a name="api.assign.by.ref"></a><div class="titlepage"></div> <div class="refnamediv"> <h2>Name</h2> <p>assign_by_ref() — assign values by reference</p> </div> <div class="refsect1" title="Description"> <a name="id3096550"></a><h2>Description</h2> <code class="methodsynopsis"><span class="type">void </span><span class="methodname">assign_by_ref</span>(<span class="methodparam"><span class="type">string </span><span class="parameter">varname</span></span>,<br> <span class="methodparam"><span class="type">mixed </span><span class="parameter">var</span></span>);</code><p> This is used to <a class="link" href="api.assign.html" title="assign()"><code class="varname">assign()</code></a> values to the templates by reference instead of making a copy. See the PHP manual on variable referencing for an explanation. </p> <div class="note" title="Technical Note" style="margin-left: 0.5in; margin-right: 0.5in;"> <h3 class="title">Technical Note</h3> <p> This is used to assign values to the templates by reference. If you assign a variable by reference then change its value, the assigned value sees the change as well. For <a class="link" href="advanced.features.html#advanced.features.objects" title="Objects">objects</a>, <code class="varname">assign_by_ref()</code> also avoids an in-memory copy of the assigned object. See the PHP manual on variable referencing for an in-depth explanation. </p> </div> <div class="example"> <a name="id3098079"></a><p class="title"><b>Example 13.4. assign_by_ref()</b></p> <div class="example-contents"><pre class="programlisting"> <?php // passing name/value pairs $smarty->assign_by_ref('Name', $myname); $smarty->assign_by_ref('Address', $address); ?> </pre></div> </div> <br class="example-break"><p> See also <a class="link" href="api.assign.html" title="assign()"><code class="varname">assign()</code></a>, <a class="link" href="api.clear.all.assign.html" title="clear_all_assign()"><code class="varname">clear_all_assign()</code></a>, <a class="link" href="api.append.html" title="append()"><code class="varname">append()</code></a>, <a class="link" href="language.custom.functions.html#language.function.assign" title="{assign}"><code class="varname">{assign}</code></a> and <a class="link" href="api.get.template.vars.html" title="get_template_vars()"><code class="varname">get_template_vars()</code></a>. </p> </div> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="api.assign.html">Prev</a> </td> <td width="20%" align="center"><a accesskey="u" href="api.functions.html">Up</a></td> <td width="40%" align="right"> <a accesskey="n" href="api.clear.all.assign.html">Next</a> </td> </tr> <tr> <td width="40%" align="left" valign="top">assign() </td> <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> <td width="40%" align="right" valign="top"> clear_all_assign()</td> </tr> </table> </div> </body> </html>