Proper way to populate / duplicate an array using ArrayAppend()

39 views
Skip to first unread message

Jeff Shood

unread,
Mar 3, 2011, 9:35:03 PM3/3/11
to Railo
Due to the differences between the way Coldfusion duplicates arrays
and how railo passes them as a reference some code I'm migrating from
ACF to Railo is breaking. I'd like to learn the right way to do this.

I'm populating an array that will be of a variable length by using the
code below: ( this is part of an error handling script)

var fileDef = arrayNew(1);
var tempArr = arrayNew(1);

tempArr[1] = "Arguments.errorMessage";
tempArr[2] = "errorMessage";
ArrayAppend(fileDef,tempArr);


if (isDefined('structCatch.ARGUMENTS.filepath') )
{
tempArr[1] = "structCatch.ARGUMENTS.filePath";
tempArr[2] = "CB_filePath";
ArrayAppend(fileDef,tempArr);
}

However because Railo passes arrays as a reference in the second block
of code where I change the value of tempArr[2] to CB_filePath, that
change is made to all elements the final array (fileDef)

Should I make a copy of tempArr each time I append to fileDef?
Should I use another function to append?
Should I be doing this a whole different way all-together?

Any advice is appreciated!

AJ Mercer

unread,
Mar 3, 2011, 10:29:36 PM3/3/11
to ra...@googlegroups.com

Michael Offner

unread,
Mar 3, 2011, 10:55:20 PM3/3/11
to ra...@googlegroups.com
Like aj write, use the function duplicate before passing the object or with cfargument/the parameter definition you can set the attribute passby="value".

/micha


Von meinem iPad gesendet

Reply all
Reply to author
Forward
0 new messages