View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > Duplicate PreviousNext

Duplicate

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

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.

Note: With this function, you cannot duplicate a COM, CORBA, or JAVA object returned from the cfobject tag or the CreateObject function. If an array element or structure field is a COM, CORBA, or JAVA object, you cannot duplicate the array or structure.

<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>

Contents > CFML Reference > ColdFusion Functions > Duplicate PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


Roman Savchenko said on Nov 26, 2003 at 9:09 AM :
I found serious bug in Duplicate() function for MX Version: 6,1,0,63958 Now this function return not a clone, but the reference on parent structure.

Shortcut on forum's topic: http://webforums.macromedia.com/coldfusion/messageview.cfm?catid=3&threadid=733835
ldpercy said on Dec 9, 2003 at 6:54 PM :
This function does not work properly on CFC instances either.
jrunrandy said on Mar 11, 2004 at 7:05 AM :
Go to http://www.macromedia.com/support/coldfusion/ts/documents/duplicate_hotfix.htm to get a hotfix that affects the duplicate function.
uesas dev team said on Oct 1, 2004 at 2:22 PM :
I have installed the hotfix. The duplicate function still converts CFC instances to structs. This is a huge disappointment.
sjibben said on Mar 29, 2005 at 1:38 PM :
Will this function work with (multi-dimensional) arrays or is there another way to make a copy of a (multi-dimensional) array?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functi74.htm