The Ultimate Var Scope Resource list? Understanding/resolving problems with the var scope in CFML
I think it's helpful to have all the resources in one place. Indeed, ultimately I'll move this to my "resource lists" page where I keep similar "compendia".
I created the list of VAR scope resources today after helping a client with a problem which seemed related to this classic problem: the need to remember to var scope your variables in CFCs. It's often the cause of subtle bugs. Like many, they still hadn't heard about the problem (or had seen mention of it but didn't really understand it).
So if you're in that place, or know someone who may be, here are resources to help get started on understanding the topic and related issues. As always, the CF community has rallied the troops on the matter, and several folks have blogged in various detail or on various related aspects.
About the resources
The first few elaborate on the problem, and the first one even includes a live running example to demonstrate the point. Then a couple explain some related issues.
I also then list resources on the related new "local" scope in CF 9, and some more that discuss compatibility issues with that.
Note that these may have been written any time in the past couple/few years, so keep that in mind and be sure to check the comments as well.
The resources
First, some general resources introducing the var scoping issue/feature:
- Thread safety and the var scope - live example, by Mike Schierberl
- Memory Leaks: Part III - sessions and cfcs, Mike's previous blog entry discussing a memory leak he'd found related to CFCs (and perhaps the var scope) back in 2006
- Why precisely is it important to var-scope your variables?, by Nathan Strutz
- Thread safety example: Var scope your loop index in ColdFusion CFCs!, by Dave Shuck
- Object Oriented Coldfusion : 4 : The var scope, by Adrian Moreno
And some that address various issues related to using the VAR scope:
- Always var scope! Always!! Except..., by Ray Camden
- Var Scoping Queries, by Gary Gilbert
- VAR scoping using structures, by Dave Shuck
- The VAR keyword is idiotic, by Steve Nelson
- The REAL reason you need to var-scope your local CFC function variables, by Tyson Vanek
And some on the change in CF9, for the local scope:
- The New ColdFusion LOCAL Scope, by Ben Forta
- Deciphering the new Local Scope, by Adam Tuttle
- Repeat - ColdFusion 9 does NOT remove the need to var scope!, by Ray Camden
And some tangential discussions of that, including some compatibility issues with the new scope:
- Be careful with the 'local' scope when migrating from CF8 to CF9, by Dan Skaggs
- CHF Warning - Impacts MXUnit, by Ray Camden (important impact of CF 9 CHF 1, even if not using MXUnit)
- LOCAL Variables Scope Conflicts With ColdFusion Query of Queries, by Ben Nadel
- Is this an issue with the local scope in ColdFusion 9?, by Paul Kukiel
- ColdFusion 9 and the local scope continued, by Paul Kukiel
- ColdFusion 9 and the LOCAL Scope, by Joseph Lamoree
- Major Flaw in CF9 - May Break Code! and part 2/part 3, by Sami Hoda
The VarScope tool
Finally, of course, as most of these resources point out, be sure to use Mike Schierberl's wonderful varscoper tool to help find whether you have instances of this problem. It tells you literally what to change, where, to don't let concern of this problem overwhelm you.
Conclusion
Hope those are helpful. Again, it's just a starting list. I welcome additions, and I look forward to your comments. In time, I'll move this (and any suggested additions) to my "resource lists" page. Check that out for similar lists of resources on various subjects.


