Hi WW,

That should be the case. The following example behaves the same in both scenarios - it's passed by reference.

<cfset struct1 = { a= 1, b = 2, c= 3 }>
<cfset struct2 = struct1>

<cfset struct2.b = 4>

<cfdump var=#variables#>

<cfset testStruct()>

<cffunction name="testStruct">
<cfset var struct1 = { a= 1, b = 2, c= 3 }>
<cfset var struct2 = struct1>

<cfset struct2.b = 4>

<cfdump var=#struct1#>
<cfdump var=#struct2#>
</cffunction>

Does that not match what you're seeing?

Andy

wcube wrote:
Hi Alan,

Thanks for the reply. I would like to ask if assigning complex data
types is pass by reference, why is it only happening in function, and
when the data is VARed? Isn't there the need to have some consistency?
Please advise.

Thanks
WW

On Jun 21, 7:36 pm, Alan Williamson<[email protected]>  wrote:
You are mistaken with the assumption that the line:

<cfset var aCategoryTest = aCategory>

is a deep copy.  It is not.  It is a copy by reference.  This is how
Java/Javascript operates.

If you wish to make a truly "deep" copy, then your best way is to use
the function Duplicate() which was designed for the very thing you are
looking for.

Hope this helps

On Jun 21, 7:25 am, wcube<[email protected]>  wrote:







I've encountered this problem that is while in a function and 'var'
the complex data type, it will be passed by reference in a way.
(tested with array and struct)


--
official tag/function reference: http://openbd.org/manual/
mailing list - http://groups.google.com/group/openbd?hl=en

Reply via email to