Function local variables

Variables that you declare with the Var keyword inside a cffunction tag or CFScript function definition are available only in the method in which they are defined, and only last from the time the method is invoked until it returns the result. You cannot use the Var keyword outside of function definitions.

Tip: You should always use the Var keyword on variables that are only used inside of the function in which they are declared.

You must define all function local variables at the top of the function definition, before any other CFML code; for example:

<cffunction ...>
   <cfset Var testVariable = "this is a local variable">
      <!--- Function code goes here. --->
   <cfreturn myresult>
</cffunction>

Any arguments declared with the cfargument tag must appear before any variables defined with the cfset tag. You can also put any cfscript tag first and define variables that you declare with the Var keyword in the script.

Use function local variables if you put the CFC in a persistent scope such as the Session scope, and the function has data that must be freed when the function exits.

Local variables do not persist between calls to CFC methods.

Local variables are available to pages included by the method.


View comments in LiveDocs