I just noticed something strange about the way CF handles arrays. I allways
thought like java CF handled everything by reference. but it seems structs
and strings are passed by reference but arrays are passed by value ? Can
anyone explain why this is ?

Pat

<h2>Arrays</h2>

<cfset a = arrayNew(1) >

<cfset a[1] = "test" >

<cfset b = a > <!--- by value --->

<cfset ArrayDeleteAt(b ,1 ) >

<cfdump var="#a#" >
<cfdump var="#b#" >

<h2>Structs</h2>

<cfset c = structNew() >

<cfset c.elem = "test" >

<cfset d = c > <!--- by reference --->

<cfset StructDelete(d,"elem") >

<cfdump var="#c#" >
<cfdump var="#d#" >


<h2>Strings</h2>

<cfset e = "test" >

<cfset f = e > <!--- by value --->

<cfset f = "" >

<cfdump var="#e#" >
<cfdump var="#f#" >

<h2>Arrays with structs</h2>

<cfset g = arrayNew(1) >

<cfset g[1] = StructNew() >
<cfset g[1].elem = "test" >

<cfset h = g > <!--- seems to copy array by value but elements by
reference --->

<cfset StructDelete(h[1],"elem") >


<cfdump var="#g#" >
<cfdump var="#h#" >



---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004

Reply via email to