Creating and using variables in scopes

The following table shows how you create and reference variables in different scopes in your code. For more information on the mechanisms for creating variables in most scopes, see Creating variables.

Scope prefix

(type)

Prefix required to reference

Where available

Created by

Application

Yes

For multiple clients in one application over multiple browser sessions. Surround code that uses application variables in cflock blocks.

Specifying the prefix Application when you create the variable.

Arguments

No

Within the body of a user-defined function or ColdFusion component method.

The calling page passing an argument in the function call.

Attributes

Yes

On a custom tag page, or inside a thread

For custom tags, the calling page passing the values to a custom tag page in the custom tag’s attributes.

For threads, the cfthread tag specifying attribute values.

Caller

On the custom tag page, Yes.

On the calling page, No (Variables prefix is optional).

On the custom tag page, by using the Caller scope prefix.

On the page that calls the custom tag, as local variables (Variables scope).

On the custom tag page, by specifying the prefix Caller when you create the variable.

On the calling page, by specifying the prefix Variables, or using no prefix, when you create the variable.

Cffile

Yes

Following an invocation of cffile.

A cffile tag.

CGI

No

On any page. Values are specific to the latest browser request.

The web server. Contains the server environment variables that result from the browser request.

Client

No

For one client in one application, over multiple browser sessions.

Specifying the prefix Client when you create the variable.

Cookie

No

For one client in one or more applications and pages, over multiple browser sessions.

A cfcookie tag. You can also set memory-only cookies by specifying the prefix Cookie when you create the variable.

Flash

Yes

A ColdFusion page or ColdFusion component called by a Flash client.

The ColdFusion Client access. You assign a value to Flash.You can assign values to the Flash.result and Flash.pagesize variables.

Form

No

On the action page of a form and in custom tags called by the action page; cannot be used on a form page that is not also the action page.

A form or cfform tag. Contains the values of form field tags (such as input) in the form body when the form is submitted. The variable name is the name of the form field.

Local

No

Within the body of a user-defined function or ColdFusion component method, only while the function executes.

Either of the following:
  • In the function or method definition, a var keyword in a cfset tag or a CFScript var statement.

  • Specifying the Local keyword when you create a variable in the function or method.

Request

Yes

On the creating page and in any pages run during the current HTTP request after the variable is created, including in custom tags and nested custom tags.

Specifying the prefix Request when you create the variable.

Server

Yes

To any page on the ColdFusion server. Surround all code that uses server variables in cflock blocks.

Specifying the prefix Server when you create the variable.

Session

Yes

For one client in one application and one browser session. Surround code that uses Session scope variables in cflock blocks.

Specifying the prefix Session when you create the variable.

This

Yes

Within a ColdFusion component or the body of a user-defined function that was created using the cffunction tag and place in an object, structure, or scope. In the containing page, through the component instance or containing object.

Within the component or function by specifying the prefix This when you create the variable.

In the containing page, by specifying the component instance or object that contains the function as a prefix when you create the variable.

ThisTag

Yes

On the custom tag page.

Specifying the prefix ThisTag when you create the variable in the tag or using the cfassociate tag in a nested custom tag.

Thread

The thread name.

Inside the thread that creates the variable, you can also use the keyword thread.

Any code in the request.

Using the keyword thread or the thread name as a prefix when you create the variable.

You can create Thread variables only inside the thread.

thread-local (no prefix)

none

Within a thread created by the cfthread tag

Using no prefix when you create the variable. You can also use the keyword var before the variable name.

URL

No

On the target page of the URL.

The system. Contains the parameters passed in the URL query string used to access the page.

Variables

(Local)

No

On the current page. Cannot be accessed by a form’s action page (unless the form page is also the action page). Variables in this scope used on a page that calls a custom tag can be accessed in the custom tag by using its Caller scope; however, they are not available to any nested custom tags.

Specifying the prefix Variables, or using no prefix, when you create the variable. (To create a Variables scope variable inside a ColdFusion thread, you must use the Variables prefix.)