views:

166

answers:

1

hi everyone, i have little impression about variables resolve order, but i can't found it in the cfml reference or coldfusion dev guide, anyone can help? great thanks.

+7  A: 

It is a generally accepted best practice to always scope your variables for two main reasons:

  • Performance - CF doesn't need to find the variable by searching through the scopes in turn
  • Accuracy - if two variables have the same name in different scopes, you may not get the one you were expecting

That said, here's the order variable scopes are searched:

  1. Function local (VAR keyword)
  2. Thread local (CFTHREAD)
  3. Query results
  4. Function ARGUMENTS
  5. Local VARIABLES
  6. CGI variables
  7. FILE variables
  8. URL parameters
  9. FORM fields
  10. COOKIE values
  11. CLIENT variables

EDIT: It's also telling to note what scopes are not searched: SESSION, SERVER, APPLICATION

Al Everett
rip747