CF documentation states the following:
"When you pass a variable to a CFML custom tag as an attribute,
or to a user-defined function as an argument, the following rules
determine whether the custom tag or function receives its own
private copy of the variable or only gets a reference to the
calling page's variable:
* Simple variables and arrays are passed as copies of the data.
If your argument is an expression that contains multiple simple
variables, the result of the expression evaluation is copied to
the function or tag.
* Structures, queries, and cfobject objects are passed as
references to the object."
HOWEVER, when I pass an array to a custom tag (.cfm), change its contents in
that tag, and then return to the calling tag, the array in the calling tag
contains the altered value. Is this a bug? Or is the documentation old and you
can now pass arrays by value?
Example:
<cfset VARIABLES.array1 = ArrayNew(1)>
<cfset ArrayAppend(VARIABLES.array1, "Original1")>
<cfset ArrayAppend(VARIABLES.array1, "Original2")>
<cfmodule template="Test.cfm"
SomeArray="#VARIABLES.array1#">
<cfoutput>#VARIABLES.array1[1]#> <!--- This shows "ALTERED". Are CF docs
wrong?--->
<cfoutput>#VARIABLES.array1[2]#> <!--- This shows "Original2" --->
--------------------------------------------------------------------------------------
Test.cfm:
--------------------------------------------------------------------------------------
<cfset ATTRIBUTES.SomeArray[1] = "ALTERED">
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:227008
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54