Gualtiero hit the nail on the head - it allows you to define a variable (or a 
variable scope aka struct) who only exists for the duration of the function's 
processing. 

'What scope is it in?' - it's in the same scope as if you omitted the 'var' 
keyword. 

<cfset myVar = 'purple' />
<cfset var myVar = 'purple' />

In both cases, your variable would be in the 'variables' scope. 

One trick that many developers like to use is to declare a variable scope for 
your functions:

<cffunction name="myFunction">
  <cfset var local = structNew() />
  <cfset local.val1 = 'blue' />
  <cfset local.val2 = 'red' />
  <cfreturn local.val1 & ' ' local.val2 />
</cffunction>

Crappy example, but hopefully it illustrates the point. By setting var local = 
structNew(), you effectively create a variable scope that only lives for the 
duration of the function. 


Jake Pilgrim

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get involved in the latest ColdFusion discussions, product
development sharing, and articles on the Adobe Labs wiki.
http://labs/adobe.com/wiki/index.php/ColdFusion_8

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:284811
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to