Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 55

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
3
If myVar is the name of a complex object, checks whether a is a complex object.
If a or myVar.a is the name of a complex object, checks whether b is the name of a simple variable, and returns the
4
value of b.
If myVar is a complex object but a is not a complex object, checks whether a.b is the name of a simple variable and
returns its value.
If myVar.a is not a complex object, checks whether myVar.a.b is the name of a simple variable and returns its value.
This way, ColdFusion correctly resolves the variable name and can get its value.
You can also use array notation to get a simple variable with a name that includes periods. In this form of array
notation, you use the scope name (or the complex variable that contains the simple variable) as the "array" name. You
place the simple variable name, in single- or double-quotation marks, inside the brackets.
Using array notation is more efficient than using plain dot notation because ColdFusion does not have to analyze and
look up all the possible key combinations. For example, both of the following lines write the value of myVar.a.b, but
the second line is more efficient than the first:
<cfoutput>myVar.a.b is: #myVar.a.b#<br></cfoutput>
<cfoutput>myVar.a.b is: #Variables["myVar.a.b"]#<br></cfoutput>
Setting a variable
ColdFusion cannot be as flexible when it sets a variable value as when it gets a variable, because it must determine the
type of variable to create or set. Therefore, the rules for variable names that you set are stricter. Also, the rules vary
depending on whether the first part of the variable name is the Cookie or Client scope identifier.
For example, assume that you have the following code:
<cfset myVar.a.b = "This is a test">
If a variable myVar does not exist, it does the following:
1
Creates a structure named myVar.
Creates a structure named a in the structure myVar.
2
Creates a key named b in myVar.a.
3
4
Gives it the value "This is a test".
If either myVar or myVar.a exist and neither one is a structure, ColdFusion generates an error.
In other words, ColdFusion uses the same rules as for getting a variable to resolve the variable name until it finds a
name that does not exist yet. It then creates any structures that are needed to create a key named b inside a structure,
and assigns the value to the key.
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#>
Last updated 1/20/2012
50

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents