Changes between Version 1 and Version 2 of FAQs/WhyAreControllerVariablesBeingIncorrectlySharedAcrossUserRequests

Show
Ignore:
Timestamp:
06/22/11 14:48:58 (15 years ago)
Author:
anonymous (IP: 67.239.128.240)
Comment:

Updated with CF9 local scope explanation

Legend:

Unmodified
Added
Removed
Modified
  • FAQs/WhyAreControllerVariablesBeingIncorrectlySharedAcrossUserRequests

    v1 v2  
    2222}}} 
    2323 
    24  
    2524This generally applies to all variables created in all CFCs for best practice. You do not need to use the "var" keyword inside .cfm pages or in Model Glue views, as there is no scope boundaries to accidentally cross. 
    2625Remember, using the "var" keyword on a variable inside a function body ensures that the variable only exists for that execution of the function. The variable is discarded after the function execution completes.  
    2726 
    2827If you need help finding areas in your code that need the "var" keyword added, download the [http://varscoper.riaforge.org/ Varscoper tool]. The Varscoper tool will scan all of your code and report back the lines that need the "var" keyword added. 
     28 
     29== A Note on !ColdFusion 9 ([http://www.coldfusionjedi.com/index.cfm/2010/2/8/Repeat--ColdFusion-9-does-NOT-remove-the-need-to-var-scope text borrowed from Ray Camden's site]) == 
     30You must still continue to var scope your variables in UDFs and CFC methods. There is no change in this respect. !ColdFusion 9 only makes two related changes: 
     31  * The var scope previous was an "unnamed" scope. ColdFusion 9 fixes this by creating a scope called 'local'. Like other !ColdFusion scopes you can treat this as a structure. 
     32  * Because there is an implicit local scope, you can now skip the var keyword and use "local." instead: 
     33    * CF8 and older:  var myVar1=1 
     34    * CF9: local.myVar1=1 
     35