tracker issue : CF-3638235

select a category, or use search below
(searches all categories and all time range)

Being able to stipulate passing data by reference

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)

Created: 09/23/2013

Components: Language

Versions: 10.0

Failure Type: Enhancement Request

Found In Build/Fixed In Build: Final /

Priority/Frequency: Trivial / Unknown

Locale/System: English / Platforms All

Vote Count: 1

Listed in the version 2016.0.0.297996 Issues Fixed doc
Verification notes: verified_fixed on August 26, 2019 using build 2016.0.01.298513

In ColdFusion (but not in Railo) for some reason, arrays are always duplicated when they are passed as function arguments or tag parameters (incl. custom tag attributes); whereas data of other complex types are passed by reference (for all intents and purposes). Here's some quick code to demonstrate:
I think ColdFusion is doing the wrong thing here, but I also think it's too late in the day to "fix" it.

What I'd like to be able to do instead is to have some sort of annotation to say "pass this thing as a reference", eg:

function arrayHandler(required &array array){

Where &array signifies and array reference, rather than the array itself.

Initially it might seem like this is limited to only arrays, but I also see it as being useful for functions which manipulate & "return" strings as well. Strings are passed by value, and strings can get rather large. So it would be useful to also be able to pass strings by reference too, I think.

Also, being able to force the opposite to occur: for objects that usually pass by reference-copy, being able to pass them by values instead would be handy. Although this is easy enough with duplicate() it'd be more syntactically elegant to be able to do it without the additional function call. This would be icing though.


----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3638235

External Customer Info:
External Company:  
External Customer Name: Adam Cameron.
External Customer Email:  
External Test Config: My Hardware and Environment details:



While I understand the base intent here, I'm wondering it if just makes more sense to "fix" the issue, so that complex data types are passed by reference and simple types by value, as one might expect...
Vote by External U.
14474 | October 09, 2013 07:19:44 AM GMT
To be considered for the next release
Comment by Rupesh K.
14471 | November 12, 2013 03:40:08 PM GMT
We are planning to address this issue at two places 1) At cfargument level with an attribute to specify whether to pass argument as reference or by value 2) A general Application level setting to affect all array argument passing specified in Application.cfc By default arrays will be passed by reference and behavior can be controlled as mentioned above. cfargument will take precedence over the application level setting (Comment added from ex-user id:sandeepp)
Comment by Adobe D.
14472 | November 14, 2014 12:47:35 AM GMT
introduced as an application level settings in the next major release of CF.
Comment by Piyush K.
14473 | June 23, 2015 06:15:32 AM GMT
Hi Adobe, I've verified this is fixed in CF2016 Update 1 (build 2016.0.01.298513). Thanks!, -Aaron
Comment by Aaron N.
31215 | August 26, 2019 04:20:34 AM GMT