tags:

views:

619

answers:

4

Are ColdFusion objects (i.e. CFCs invoked via cfobject) normally passed by reference or by value (copied in memory)? And is it possible to force ColdFusion to pass an object in either manner?

+18  A: 

ColdFusion objects are passed by reference. There's not really a way to pass an object by value, but you can create a copy using the duplicate() function.

Patrick McElhaney
+13  A: 

Well, keep in mind that using duplicate() doesn't work in MX 7 for copying certain things, like CFCs and COM, CORBA, and Java objects. You can copy a CFC in CF 8, though.

Dave DuPlantis
+9  A: 

Complex objects such as structs and CFCs are passed by reference, but if you pass an array to a UDF it is passed by value. This makes it impossible to write a user defined function that mutates an array like the built-in array functions do. If you really need to pass an array by reference, you can wrap it in a struct, and then it will be passed by reference.

+3  A: 

FWIW, arrays are also passed by reference in the Railo CFML engine, as many developers believe they should. Railo 3.1 is also expected to offer an administrative setting to allow you to choose the default behavior, for optional compatibility with Adobe CF.

Jamie Krug