ColdFusion Variable Scopes

The need to understand how ColdFusion handles variable scopes is essential to keeping both your application and server running smoothly and preventing performance decreases.  Scoping your variables takes seconds at the time of development.  I frequently talk with customers who have ‘memory leaks’ and are quick to blame the application server, however a ColdFusion application server that doesn’t run code would not typically experience a leak.
The Scopes
 
Order of Evaluation
Should you specify a variable name with out a scope, ColdFusion has to search through the different scopes in order to determine if it exists.  As you might imagine, if this is on a very frequently requested page, this could cause significant slow-downs and performance issues.

  1. Function local (only UDFs and CFCs)
  2. Thread local (only inside threads)
  3. Arguments
  4. Variables
  5. Thread
  6. CGI
  7. Cffile
  8. URL
  9. Form
  10. Cookie
  11. Client

If the variable exists in any of the other scopes, it must be scoped properly to be accessed.
Additional Reading

 

Leave a Reply

Your email address will not be published. Required fields are marked *