On 5/31/05, Darryl Lyons <[EMAIL PROTECTED]> wrote: > Aren't arrays passed by value into methods?
Yes, so I was a little surprised to see Gareth's claim that he got two elements back in CF6. So I tried it on CF6.1 and 6.1.1 and, yes, he's right. Weird. But I definitely would have expected it to pass the array by value. I did a bit more digging. If you assign an array it does it by value not by reference: <cfset a1 = arrayNew(1)> <cfset a1[1] = "Hello"> <cfset a2 = a1> <cfset a2[2] = "World"> Dump both of those and you'll find a1 still has just "Hello" but a2 has both. Similarly, if you now change a1[1] to "Goodbye" you'll see that a2 is unaffected. True in CF6.1 and 6.1.1 and 7.0. Now look at return values. If you return an array, it returns by value. I'm not going to show the test code here but I tested it and confirmed that it is by value (have a method return variables.someArray, modify it in the calling code and then call back into the CFC - variables.someArray is unmodified. Similarly, return variables.someArray and then call a method that modifies it inside the CFC - outside the CFC the previously returned array is unchanged). Now, CF7 treats array arguments as pass by value - in line with assignments and returns. CF6.1 / CF6.1.1 treats array assignment and return as by value but passes arguments by reference. I can only deduce from this that it was considered a bug in CF6.1 that got fixed in CF7 so that arrays were treated consistently. -- Sean A Corfield -- http://corfield.org/ Team Fusebox -- http://fusebox.org/ Got Gmail? -- I have 50, yes 50, invites to give away! "If you're not annoying somebody, you're not really alive." -- Margaret Atwood --- You are currently subscribed to cfaussie as: [email protected] To unsubscribe send a blank email to [EMAIL PROTECTED] Aussie Macromedia Developers: http://lists.daemon.com.au/
