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:
- 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
Al Everett
2009-07-20 13:17:20
rip747
2009-07-20 20:44:30