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?
相关问题
- JavaScript variable scope question: to var, or not
- How to specify argument attributes in CFscript? (C
- Coldfusion date conversion: “2013-11-15T06:11:57.8
- Scope on each last elements of a has_many relation
- Batch - Set variables in for loop
相关文章
- How do I prevent SQL injection with ColdFusion
- Loss of variables switching orientations
- What is the limit in size of a Php variable when s
- Rails scope for values only between two dates
- How to scope closure's variables in CF10?
- What Notable Differences are there between Railo,
- Makefile and use of $$
- Restarting ColdFusion mail queue
It is a generally accepted best practice to always scope your variables for two main reasons:
That said, here's the order variable scopes are searched:
EDIT: It's also telling to note what scopes are not searched: SESSION, SERVER, APPLICATION
Scope Order
The canonical scope order for ColdFusion 9 is:
You can see Adobe's documentation on this in Developing ColdFusion 9 Applications.
However, some scopes are only available in certain contexts, so the order that scopes are searched is different, depending upon the context of the code.
Inside CFML (no threads)
Inside a CFC (no threads)
Best Practice
As Al Everett notes in his answer, it is considered best practice to always scope variables. Explicit scoping produces less ambiguous code and is usually faster. Anytime you don't scope a variable, you risk getting a variable from a scope that you didn't intend to.