Viewing Individual Entry / Main
  ::   September 30, 2002

By Reference/By Value
As you know, or should know, when you pass in structures, or queries, or COM objects, or arrays of structs, to a UDF or Custom Tag, you are passing them by reference, not value. This means if you modify the value in the UDF or CT, the original is modified. Most of the time you don't care since you actually want to modify the original...

However if you want to work on a copy, you would need to use duplicate:

You should note that the same rule applies when returning values from a CFC - if and only if you are returning a persisted value. What does this mean? Imagine a persisted CFC (and this doesn't mean it exists in the application, sessiom, or server scope, it means ANY CFC that you have made an object instance of). Imagine that the CFC has a value that exists outside of the method, either in the This scope or in the private scope. Something like so:

If you create an instance of this CFC and then call get A, you will have a structure returned. However, if another method of the CFC modifies this A, it will modify your structure as well. To correct this, simply add duplicate to the return tag:



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
Things Fall Apart : A Novel

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