Viewing Individual Entry / Main
  ::   September 18, 2002

Bug Passing Arrays by Value to Tag Based UDFs in CFMX
I was finishing up the example code for my DevCon presentation on User Defined Functions in ColdFusion MX when I discovered what looks like a bug in how tag based UDFs treat arrays passed in as arguments. ColdFusion is supposed to pass arrays by value, meaning that a copy of the array is passed. This means that anything the UDF does to the array affects only the copy of the array, and not the original. In CFMX tag based UDFs, however, it looks like arrays are being passed by reference, meaning that a reference to the original is being passed in, and not a copy. This means that any modifications the UDF makes to the array are actually made to the original as well. This can be a bad thing if you aren't expecting it. To demonstrate, check out the following code:

Before

Inside the UDF

After

If you look at the "After", you'll notice that the 4th array index is still there - and it shouldn't be. This has been logged as a bug with Macromedia.

As a workaround you can make your UDF in CFSCRIPT as script based UDFs aren't affected. If you must have tag based functionality, you can work around the problem by making a copy of your array first using the duplicate() function.



Calendar
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

Recommended Reading
Ishmael: An Adventure of the Mind and Spirit

Archives by Subject
Announcements (28)
ColdFusion (61)
Database (12)
Dreamweaver (1)
Flash (2)
Flash Remoting (2)
Flex (3)
General Development (2)
Homesite + (1)
Mach-II (3)
MAX (9)
Mozilla (2)
Music (1)
Politics (1)
Portals (2)
Travel (2)

Search

Links
CFLib.org
Raymond Camden's Blog
Christian Cantrell's Blog
Sean Corfield's Blog
Nathan Dintenfass' Blog
Todd Rafferty's Blog
Steve Rittler's Blog
Cameron Childress's Blog

Credits
Based on blog.cfc by Raymond Camden

XML Feed