Creating variables with periods



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 Structure notation. To do so, you must do the following:

  • Reference 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.

  • Place the variable name that must include a period inside 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">