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#">
  • 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...
    – user7043
    May 3, 2011 at 19:52
  • 1
    @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. May 3, 2011 at 20:57
  • 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, 2011 at 18:20

1 Answer 1


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;
  • That is what I thought, but I couldn't find any clear documentation. Thanks!
    – Evik James
    May 4, 2011 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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