I have heard others mention Duplicate() in the context of data integrity, and I would like to get a better understanding of how it works and when to use it.
I often see this:
<cfreturn Duplicate(local.myVariable)>
When this also returns the same result:
<cfreturn local.myVariable>
While most variables are passed by value in ColdFusion, Structures are not -- they are passed by reference, which can cause unintentional overwriting of values, if you aren't careful.
Using Duplicate()
creates an identical copy of the variable in another location in memory, so that when it is passed by reference (note that you are still passing by reference, there is no way to force a pass by value) any changes made to the data from the caller do not affect the source of the return.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With