Reputation: 15200
What is be the best way to define method level variables scope?
Some ColdFusion documents say it should be done like this:
<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?
Upvotes: 3
Views: 130
Reputation: 473
Either will work.
In CF9 (and I assume 10) var local = structNew() is unnecessary (though harmless and makes your code backward compatible) as there is within each function a local scope that contains any locally scoped values. Also with CF8 and earlier these variables will need to be the first thing declared in a function.
So to specifically answer your question I prefer the var local = structNew() (or just var local={}) because:
Upvotes: 4