Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am starting to use the LOCAL scope in ColdFusion 9. I am trying to figure when to use it and when NOT to use it. Can you tell me the advantages/disadvantages of using the LOCAL scope either way? Should LOCAL be used on every page, or just in functions?


<cfset ImageHeight = 36>  
<cfset ImageWidth = 42>  
<img src="" height="#ImageHeight#" width="#ImageWidth#">


<cfset LOCAL.ImageHeight = 36>  
<cfset LOCAL.ImageWidth = 42>  
<img src="" height="#LOCAL.ImageHeight#" width="#LOCAL.ImageWidth#">
share|improve this question
Wait, does that mean you have to add six characters, five of which are ugly upper-case, to get any scoping (except global one) in ColdFusion? Wow. And people are bitching about PHP... – delnan May 3 '11 at 19:52
@delnan - the casing is a personal preference in coding style and is nothing to do with ColdFusion. The local scope, as Justice has already pointed out, is only usable in functions in ColdFusion 9. Access to other scopes in ColdFusion is not that different to PHP. – Stephen Moretti May 3 '11 at 20:57
@Stephen: Thanks for the good news :) – delnan May 4 '11 at 13:17
I always use upper case for scoping. It's not required. Since I have nothing else in all caps, it makes the scope easier to read. – Evik James May 4 '11 at 18:20
up vote 3 down vote accepted

The local scope is defined only within functions.

function a() {
  //this way
  var myVariable = 0;
  //is the same as this way (in CF9)
  local.myVariable = 0;

Do not use the local scope outside functions.

Outside functions, variables default to the variables scope.

//this way
myVariable = 0;
//is the same as this way
variables.myVariable = 0;
share|improve this answer
That is what I thought, but I couldn't find any clear documentation. Thanks! – Evik James May 4 '11 at 18:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.