Sorry to yell (well, we don't have to assume all exclamation marks are equivalent to yelling) but this email came in to me this morning and it is very troubling for me:
I have a question for you about varScoper and CF9. As I understand it, in CF9 all unscoped variables in a function are placed into a protected local scope, thereby killing the need to use the var x = "" line to scope them.If that understanding is correct, does this make varScoper obsolete in CF9? Our team in upgrading to CF9 in the near future, and trying to identify if running code through varScoper needs to continue to be a part of our code review processes or not.
The answer is an unequivocal no. You 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:
- 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.
- Because there is an implicit local scope, you can now skip the var keyword and use "local." instead. So given the line used in the quote above, you could var scope X by rewriting it as local.x="". To me, this is still "var scoping", it just gets there via a different path.
So long story short - yes - you still need to var scope in CF9. The varScoper tool is still an important and necessary part of your testing/deployment strategy.


Comment 1 written by John gag on 8 February 2010, at 2:16 PM
Comment 2 written by Seth Johnson on 8 February 2010, at 2:27 PM
Comment 3 written by Raymond Camden on 8 February 2010, at 2:28 PM
Comment 4 written by Jose Galdamez on 8 February 2010, at 6:22 PM
cfset var local = {};
and then appending to the struct from there. I realize this is nothing earth shattering as people were doing it years before I even figured it out. What killed me was when I did this by accident in several places
cfset local = {};
That's when I started pulling my hairs out, in pure denial that I did anything wrong. Ugh.
Comment 5 written by Dan Roberts on 9 February 2010, at 9:41 AM
Comment 6 written by Raymond Camden on 9 February 2010, at 9:58 AM
Comment 7 written by Allen on 9 February 2010, at 12:11 PM
Comment 8 written by Raymond Camden on 9 February 2010, at 12:14 PM
local.x = 1
is the same as
var x = 1
Comment 9 written by Judah McAuley on 11 February 2010, at 3:56 PM
For instance if I do:
<cfhttp url="http://foo.com">" target="_blank">http://foo.com">
and reference #cfhttp.filecontent#
That is not threadsafe!
Totally bit me in the ass on a production application.
Instead you need to do:
<cfset var httpresult = '' />
<cfhttp url="http://foo.com" result="httpresult">
and then reference #httpresult.filecontent#
I had var scoped every variable in my app...except for the one I didn't create myself and let CF create for me.
Comment 10 written by Raymond Camden on 11 February 2010, at 3:58 PM
Comment 11 written by Julie on 6 May 2010, at 8:19 PM
Comment 12 written by Raymond Camden on 6 May 2010, at 8:25 PM
[Add Comment] [Subscribe to Comments]