In ColdFusion, variables are resolved in what order?

coldfusion, scope, variables

Solution

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:

- Function local (VAR keyword)

- Thread local (CFTHREAD)

- Query results

- Function ARGUMENTS

- Local VARIABLES

- CGI variables

- FILE variables

- URL parameters

- FORM fields

- COOKIE values

- CLIENT variables

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

Problem

I have little impression about variables resolve order, but I can't find it in the CFML Reference or ColdFusion Dev Guide. Can anyone help?

Original source