Determining the level of the Coldfusion method

What is the best way to determine the scope of method level variables?

Some ColdFusion docs say this should be done as follows:

 <cfset Var testVariable = "this is a local variable">

But others, do it like this:

<cfset LOCAL = StructNew() />
<cfset LOCAL.testVariable  = StructNew() />

Which way is better?

+3
source share
1 answer

Or everything will work.

In CF9 (and I assume 10), var local = structNew () is not necessary (albeit harmless, and makes your code backward compatible), since inside each function there is a local area containing any locally-cloud values. Also with CF8 and earlier, these variables must be the first ones declared in the function.

To specifically answer your question, I prefer var local = structNew () (or just var local = {}) because:

  • , , , (var ).
  • "" cf 8.
+4

All Articles