ColdFusion Scopes

  • Post author:
  • Post category:Uncategorized

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):

  1. Function local (UDFs and CFCs only)
  2. Arguments
  3. Variables (local scope)
  4. CGI
  5. Cffile
  6. URL
  7. Form
  8. Cookie
  9. Client

Remember, always do 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.