Returns a clone, also known as a deep copy, of a variable. There is no reference to the original variable.
A clone of a variable.
Structure functions, System functions
Duplicate(variable_name)
StructCopy, other Structure functions; "Modifying a ColdFusion XML object" in the ColdFusion Developer's Guide
ColdFusion 8: Changed behavior: this function can duplicate CFCs.
ColdFusion MX: Changed behavior: this function can be used on XML objects.
Parameter |
Description |
---|---|
variable_name |
Name of a variable to duplicate |
Use this function to duplicate complex structures, such as nested structures and queries.
When you duplicate a CFC instance, the entire CFC contents is copied, including the values of the variables in the this scope at the time you call the Duplicate function. Thereafter, the two CFC instances are independent, and changes to one copy, for example by calling one of its functions, have no effect on the other copy.
<h3>Duplicate Example</h3> <cfset s1 = StructNew()> <cfset s1.nested = StructNew()> <cfset s1.nested.item = "original"> <cfset copy = StructCopy(s1)> <cfset clone = Duplicate(s1)> <!--- modify the original ---> <cfset s1.nested.item = "modified"> <cfoutput> <p>The copy contains the modified value: #copy.nested.item#</p> <p>The duplicate contains the original value: #clone.nested.item#</p> </cfoutput>