Downloads

Download the ColdFusion Scopes Quick Reference (PDF)

ColdFusion scopes Quick reference

Adobe ColdFusion (ACF) and Lucee CFML highlights, thread-safety tips, and safe scoping patterns.

Scope Summary

ScopeLifetimeVisibilityThread-Safe?Typical UsageNotes
localFunction callWithin functionYesTemporary varsUse local.x or var x (tags)
argumentsFunction callWithin functionYesFunction paramsAccess as arguments.foo
variablesCFC/TemplatePer CFC instance or pagePer-instancePrivate CFC stateIn CFCs, use for private fields
thisCFC lifetimePublic membersPer-instancePublic APIDo not store request/user data here
requestSingle requestAll code in requestYesShare per-request dataAvoid leaking to broader scopes
sessionUser sessionPer userNo (lock)User prefs/loginUse named locks for writes
applicationApp lifecycleAll usersNo (lock)App-wide configInitialize once with locking
serverEngine uptimeWhole CF engineNo (lock)Global caches/flagsUse sparingly
formRequestCurrent requestn/aForm inputValidate & sanitize
urlRequestCurrent requestn/aQuery stringValidate & sanitize
cookieClientPer clientn/aUser tokensHttpOnly/Secure/SameSite
cgiRequestCurrent requestn/aHeaders/envDo not trust blindly
clientConfiguredPer clientn/aOptional persistenceConsider DB-backed session instead

Best practices

  • Always qualify variables: local, arguments, variables, etc.
  • Lock application and session writes with named locks.
  • Whitelist and validate form/url before use.
  • Use this for public API, variables for private state in CFCs.
  • Prefer request for per-request cache/state.

Examples

// CFScript function scoping
function calcTotal(required numeric price, numeric tax=0) {
  var total = price + (tax ?: 0);
  return total;
}

// Locking session writes
lock name="session.user" type="exclusive" timeout=5 {
  session.user = { id = 123, name = "Ada" };
}

// Safe input
if (!isValid("integer", url.id)) { throw(type="BadInput", message="Invalid id"); }
See also  Download the ColdFusion Backup & Restore Runbook (PDF)

About the author

Aaron Longnion

Aaron Longnion

Hey there! I'm Aaron Longnion — an Internet technologist, web software engineer, and ColdFusion expert with more than 24 years of experience. Over the years, I've had the privilege of working with some of the most exciting and fast-growing companies out there, including lynda.com, HomeAway, landsofamerica.com (CoStar Group), and Adobe.com.

I'm a full-stack developer at heart, but what really drives me is designing and building internet architectures that are highly scalable, cost-effective, and fault-tolerant — solutions built to handle rapid growth and stay ahead of the curve.