User Guide

Table Of Contents
58 Chapter 3: Using ColdFusion Variables
However, if the name before the first period is either Cookie or Client, ColdFusion uses a
different rule. It treats all the text (including any periods) that follow the scope name as the name
of a simple variable, because Cookie and Client scope variables must be simple. If you have the
following code, you see that ColdFusion creates a single, simple Client scope variable named
myVar.a.b:
<cfset Client.myVar.a.b = "This is a test">
<cfdump var=#Client.myVar.a.b#>
Creating variables with periods
You should avoid creating the names of variables (except for dot notation in structures) that
include periods. However, ColdFusion provides mechanisms for handling cases where you must
do so, for example, to maintain compatibility with names of variables in external data sources or
to integrate your application with existing code that uses periods in variable names. The following
sections describe how to create simple variable names that include periods.
Using brackets to create variables with periods
You can create a variable name that includes periods by using associative array structure notation,
as described in Chapter 5, “Structure notation,” on page 109. To do so, you must do the
following:
Refer to the variable as part of a structure. You can always do this, because ColdFusion
considers all scopes to be structures. For more information on scopes, see “About scopes
on page 64.
Put the variable name that must include a period inside square brackets and single- or double-
quotation marks.
The following example shows this technique:
<cfset Variables['My.Variable.With.Periods'] = 12>
<cfset Request["Another.Variable.With.Periods"] = "Test variable">
<cfoutput>
My.Variable.With.Periods is: #My.Variable.With.Periods#<br>
Request.Another.Variable.With.Periods is:
#Request.Another.Variable.With.Periods#<br>
</cfoutput>
Creating Client and Cookie variables with periods
To create a Client or Cookie variable with a name that includes one or more periods, simply
assign the variable a value. For example, the following line creates a Cookie named
User.Preferences.CreditCard:
<cfset Cookie.User.Preferences.CreditCard=”Discover”>