ACF's behavior runs counter to pretty much every other language I've worked with (shallow copying arrays on assignment) and it's inefficient to boot. I believe Railo offers an Administrator option to change to the less efficient / more compatible behavior but it's not something that will get changed in the core engine.
Note that the following does *not* cause a copy and *will* append to the array in ACF: <cfset arrayAppend(o.getNumbers(), "wha")> <cfdump var="#aNumbers1#"> <cfset arrayAppend(o.getNumbers(), "wha")> <cfdump var="#aNumbers2#"> Sean On Sat, Oct 16, 2010 at 9:31 AM, Adam Cameron <[email protected]> wrote: > G'day > This is an inconsistency with CF that Railo shares with BD. I'm not > sure why my tests show this up on Railo but not BD though... I need to > look at that... hmmm... > > Anyway, some code: > > <!--- Numbers.cfc ---> > <cfcomponent> > > <cfset variables.aNumbers = listToArray("tahi,rua,toru")> > > <cffunction name="getNumbers" returntype="array"> > <cfreturn variables.aNumbers> > </cffunction> > > </cfcomponent> > > <!--- caller.cfm ---> > <cfset o = createObject("component", "Numbers")> > > <cfset aNumbers1 = o.getNumbers()> > <cfset arrayAppend(aNumbers1, "wha")> > <cfdump var="#aNumbers1#"> > > <cfset aNumbers2 = o.getNumbers()> > <cfset arrayAppend(aNumbers2, "wha")> > <cfdump var="#aNumbers2#"> > > Now, because - I guess - CF copies the array when it's assigned to a > new variable, I just end up with "tahi, rua, toru, wha" in the second > dump (which is what I'd expect). On BD (Open & .NET), and Railo, I > guess it's just referencing the one array throughout, so I get "tahi, > rua, toru, wha, wha". > > I realise the way CF handles arrays is a bit of an idiosyncracy cf > other complex data types, but given the precedent is set, should not > the other engines follow suit? > > [...] > > -- > Adam > > -- > Open BlueDragon Public Mailing List > http://www.openbluedragon.org/ http://twitter.com/OpenBlueDragon > official manual: http://www.openbluedragon.org/manual/ > Ready2Run CFML http://www.openbluedragon.org/openbdjam/ > > mailing list - http://groups.google.com/group/openbd?hl=en > -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood -- Open BlueDragon Public Mailing List http://www.openbluedragon.org/ http://twitter.com/OpenBlueDragon official manual: http://www.openbluedragon.org/manual/ Ready2Run CFML http://www.openbluedragon.org/openbdjam/ mailing list - http://groups.google.com/group/openbd?hl=en
