I was following a discussion about scopes on the CF-Talk mailing list today. If you don’t specify a scope for a variable, ColdFusion will search all of the scopes until it finds it (if it exists). Of course, it is best to specify a scope because it improves performance, plus removes possible scope errors (two variables with the same name). However, if you are curious, here is the order that CF checks scopes (this is CF MX, not sure about previous versions):
- Function local (UDFs and CFCs only)
- Arguments
- Variables (local scope)
- CGI
- Cffile
- URL
- Form
- Cookie
- Client
Remember, always do #url.id# istead of just #id#! 🙂Update: nick left a comment asking about the Request scope. Jura points out that ‘Request’ is required, therefore there’s no need for ColdFusion to search this scope. I looked in LiveDocs, and found these scopes where the prefix is required: Attributes, Caller (on the custom tag page), ThisTag, Request, Cffile, Session, Application, Server, Flash, and This.