COLDFUSION CFARGUMENT content changes

I have the below program. Can somebody point out why the content of parmArray in function "doCalc"  changes whle
no operation is being performed on it.

I have been pulling my hair on this issue for about 2 days now.

Any help is greatly appreciated.



<cfset aAr1 = arrayNew(1)>
<cfset s = structNew()>
<cfset s.date = 'xx'>
<cfset s.interest = '250'>
<cfset aAr1[1] = s>
<cfset s = structNew()>
<cfset s.date = 'yy'>
<cfset s.interest = '300'>
<cfset aAr1[2] = s>
<cfset s = structNew()>
<cfset s.date = 'zz'>
<cfset s.interest = '350'>
<cfset aAr1[3] = s>


<cfinvoke   method="doCalc" returnvariable="aResult1">
    <cfinvokeargument name="parmArray"  value="#aAr1#">
</cfinvoke>


<cffunction name="doCalc" returntype ="array">
    <cfargument name="parmArray" required="true" type="array">

      <cfdump var = "#parmArray#" label="before">
      <cfset LOCAL.aAr2 = parmArray>
      
      <cfloop index="LOCAL.nIDX" from="1" to="#arrayLen(LOCAL.aAr2)#" >
            <cfset LOCAL.aAr2[LOCAL.nidx].date = LOCAL.nIdx>
      </cfloop>

      <cfdump var = "#parmArray#" label="after">      
      
    <cfreturn LOCAL.aAr2>
 </cffunction>
Errol FarroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gdemariaCommented:
<cfset LOCAL.aAr2 = parmArray>

  This is creating a reference to the same structure.

  You can copy the structure using  structCopy or just create the copy while looping through, otherwise, it is just a pointer to the same structure
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Errol FarroAuthor Commented:
Thanks for the pointer. It worked !!!!!!!!
0
_agx_Commented:
Keep in mind structCopy does a shallow copy.  Meaning any complex objects within the array will still be a "reference" to the original. If the result should be a completely separate copy, use duplicate() instead.
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.