Trainings

Friday, July 3, 2009

Coldfusion 9

Define a variable local to function
--------------------------------------
Variables in this scope exist only during the execution of the function and are available only to the function.

In Coldfusion 9 we got the "local" scope as any other scope like variables,application.

To declare a function-local scope variable either specify the Local scope name when assigning the variable, or use the var keyword.
Also, you can now use the var keyword anywhere in a function definition, not just at the top.

For example:


<cffunction name="foo" output="true">
<cfset var x = 5>
<cfset local.y=local.x*4> <!--- Now define local variable using local.varname --->
<cfset var z=[local.x,local.y]> <!--- now use the var keyword anywhere in a function definition, not just at the top. --->
<cfset zz="in Variables Scope">
<cfdump var="#local#"> <!--- Also you can dump local scope as any other scope --->
</cffunction>