coldfusion Variables Setting a variable scope


Example

It is a common practice to set application variables to an object scope. This keeps them easy to identify and distinguish from variables in other scopes.

The Variables scope in a CFC is private to the CFC. When you set variables in this scope, they cannot be seen by pages that invoke the CFC.

<cfparam name="variables.firstName" default="Timmy">
<cfset variables.firstName="Justin">

Scopes shared with the calling page include: Form, URL, Request, CGI, Cookie, Client, Session, Application, Server, and Flash. Variables in these scopes are also available to all pages that are included by a CFC.

CFC:

<cfset url.sessionId="23b5ly17">

<cfinclude template="check_session.cfm">

check_session.cfm

<cfif url.sessionId eq "23b5ly17">
    <p>Welcome back!</p>
</cfif>