I have been programming ColdFusion for over 15 years, but have never met this. Here is the code for replicating behavior:
<cfset _run()> <cffunction name="_run"> <cfset variables.dataArray=ArrayNew(1)> <cfset local.data={ area="profile" }> <cfset _append(data=local.data,field="name")> <cfset _append(data=local.data,field="phone")> <cfdump var="#variables.dataArray#" label="dataArray"> </cffunction> <cffunction name="_append"> <cfargument name="data" type="struct" required="yes"> <cfargument name="field" type="string" required="yes"> <cfdump var="#arguments#" label="arguments"> <cfset arguments.data.field=arguments.field> <cfset ArrayAppend(variables.dataArray,arguments.data)> </cffunction>
As you can see, this is what I am doing:
- Inclusion of an array in a variable region to make it accessible to the whole world
- Entering a structure (local.data) in the local area
- Adding the first field element (name) by calling the _append function data
- Adding a second field element (phone) in the same way
This code will lead to the following output:

As you can see, the code leads to an array with duplicate entries, when you can expect the first index to have a field = "name". As you can also see, the data value that is called for _append a second time contains the "field" property with the value "name". Does it seem to linger in the argument field the first time we called a function? How is this possible. I thought the argument area was isolated inside the cffunction tag?
But if I replaced the _append function as follows:
<cffunction name="_append"> <cfargument name="data" type="struct" required="yes"> <cfargument name="field" type="string" required="yes"> <cfdump var="#arguments#" label="arguments"> <cfset local.data=Duplicate(arguments.data)> <cfset local.data.field=arguments.field> <cfset ArrayAppend(variables.dataArray,local.data)> </cffunction>
he will give the following result:

As you can see, duplicating the arguments. data before adding "fields" to it, solves the problem. Note that it is simple:
<cfset local.data=arguments.data>
was not enough.
Can someone explain this behavior of the argument field?
source share