Lesson  in  ColdFusion 2025: Foundations

Variables, Data Types & Scopes

Understand how ColdFusion manages variables, the available data types, and the critical concept of variable scopes.

Data types

ColdFusion is dynamically typed. Variables are created on assignment and their type is inferred at runtime — no int, String, or var declarations required.

TypeExampleNotes
String"Hello"Immutable; & concatenates
Numeric42, 3.14Integer and float unified
Booleantrue, false, yes, noyes/no are aliases
Datenow(), "2026-09-03"Rich date/time functions built in
Array[1, 2, 3]1-based index
Struct{name: "Alex", age: 30}Key-value map; keys case-insensitive
Queryresult of cfquery / queryExecute()Tabular result set
[object Object]

CFML's six core data types — dynamically inferred at runtime, no explicit type declarations needed.

Activity: Click the Terminal tab in your lab. Once the terminal is open, copy and paste the script below to create data_types.cfm and explore all six data types:

sudo tee /opt/coldfusion2025/cfusion/wwwroot/data_types.cfm << 'EOF'
<cfscript>
  // String
  myString = "Hello ColdFusion";
  writeOutput("<strong>String:</strong> " & myString & "<br>");

  // Numeric
  myInt  = 42;
  myFloat = 3.14;
  writeOutput("<strong>Numeric:</strong> " & myInt & " / " & myFloat & "<br>");

  // Boolean
  isActive = true;
  writeOutput("<strong>Boolean:</strong> " & isActive & "<br>");

  // Date
  today = now();
  writeOutput("<strong>Date:</strong> " & dateFormat(today, "yyyy-mm-dd") & "<br>");

  // Array
  fruits = ["apple", "banana", "cherry"];
  writeOutput("<strong>Array[1]:</strong> " & fruits[1] & "<br>");

  // Struct
  person = {name: "Alex", age: 30};
  writeOutput("<strong>Struct:</strong> " & person.name & " is " & person.age & "<br>");
</cfscript>
EOF

Open /data_types.cfm in the ColdFusion 2025 browser tab (right-click → Open Link in New Tab, then change the path). Or from the Terminal:

curl -s http://localhost:8500/data_types.cfm
[object Object]

All six data types rendered — each line shows the type name and its value.


Variable scopes

ColdFusion organises variables into named scopes. Every scope has a different lifetime and visibility.

ScopePrefixLifetimeTypical use
variablesvariables.Single requestDefault local scope for a page/CFC
urlurl.Single requestQuery-string parameters
formform.Single requestPOST form fields
requestrequest.Single requestPass data between included files
sessionsession.User sessionPer-user state (cart, login)
applicationapplication.App lifetimeShared config, counters
serverserver.Server lifetimeRarely written; read CF/Lucee version

The variables scope is the default when you omit a prefix. Always prefix session.* and application.* explicitly.

[object Object]

Scope lifetimes compared — request-scoped variables are cheapest; application-scoped variables persist for the life of the process.

Activity: Still in the Terminal tab, copy and paste the script below to create scopes.cfm and demonstrate the variables scope explicitly:

sudo tee /opt/coldfusion2025/cfusion/wwwroot/scopes.cfm << 'EOF'
<cfscript>
  // variables scope — explicit prefix
  variables.name    = "Alex";
  variables.course  = "ColdFusion 2025";

  writeOutput("<strong>variables.name:</strong> "   & variables.name   & "<br>");
  writeOutput("<strong>variables.course:</strong> " & variables.course & "<br>");

  // url scope — reads ?name= from the query string
  urlName = url.name ?: "no name passed";
  writeOutput("<strong>url.name:</strong> " & urlName & "<br>");
</cfscript>
EOF

Open /scopes.cfm in the browser to confirm the variables scope output:

curl -s http://localhost:8500/scopes.cfm
[object Object]

scopes.cfm with no query string — variables.* values are set, url.name falls back to the default.


Now verify that the variables. prefix is used explicitly in the file:


URL scope

Pass a query-string parameter and read it back with url.name:

curl -s "http://localhost:8500/scopes.cfm?name=TestUser"
# Expected: url.name: TestUser

Or in the browser, append ?name=TestUser to the URL:

https://<your-session-id>.iximiuz.com/scopes.cfm?name=TestUser
[object Object]

With ?name=TestUser appended, url.name resolves to TestUser instead of the default.


Scope resolution order

[object Object]

When you omit a scope prefix, CF walks this resolution chain top-to-bottom — always prefix to be explicit.

When you write just name without a prefix, ColdFusion checks scopes in this order:

  1. local (inside a CFC function)
  2. arguments
  3. thread
  4. query (inside a <cfloop query="...">)
  5. variables
  6. cgi, file, url, form, cookie, client

Always prefix to be explicit and avoid scope-bleed bugs. In a large application, an unqualified variable that accidentally resolves from url instead of variables can cause hard-to-trace security issues.

Need to inspect all scope values at once?

ColdFusion has a built-in debugging tool — cfdump. It renders any variable, struct, array, or scope as a formatted HTML table, perfect for exploring what's actually in scope at runtime.

<cfdump var="#variables#" label="variables scope">
<cfdump var="#url#"       label="url scope">
<cfdump var="#session#"   label="session scope">

Add those lines temporarily to any .cfm file, reload in the browser, and you get a complete view of every variable in each scope. Remove them before going to production.

Need to edit a file? Use vi

If you need to tweak scopes.cfm without rewriting it from scratch:

vi /opt/coldfusion2025/cfusion/wwwroot/scopes.cfm
KeyWhat it does
iEnter insert mode
EscBack to normal mode
:wq + EnterSave and quit
:q! + EnterQuit without saving

When all the checks above are green, this lesson is complete. Your progress is saved automatically — move straight on to the next lesson.