Note: This blog post is from 2010. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.If you or anyone you know ever wants to get up to speed on the "var scope problem" in CF, you may be challenged by the fact that there are many discussions of the topic, spread across many blogs. I've accumulated here a starting list of several of the key ones I know of. I certainly may have missed some, so I welcome suggestions of more.
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.
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 (recovered via archive.org)
- Object Oriented Coldfusion : 4 : The var scope, by Adrian Moreno
And some that address various issues related to using the VAR scope:
- So what happens when you don't var scope? and 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
- 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 (recovered via archive.org)
- ColdFusion 9 and the local scope continued, by Paul Kukiel (recovered via archive.org)
- Major Flaw in CF9 - May Break Code! and part 2/part 3, by Sami Hoda
The VarScope toolFinally, 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.
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.
For more content like this:
Need more help with problems?
- Signup to get my blog posts by email:
- Follow my blog RSS feed
- View the rest of my blog posts
- View my blog posts on the Adobe CF portal
- If you may prefer direct help, rather than digging around here/elsewhere or via comments, I can help via my consulting services
- See that for more on how I can help a) over the web, safely and securely, b) usually very quickly, c) teaching you as we go, and d) with satisfaction guaranteed