Adobe COLDFUSION 9 Manual page 54

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
ColdFusion behavior is less straightforward, however, when you use the query column references myQuery.Firstname
and myQuery["Firstname"] without using an array index. The two reference formats produce different results.
If you reference myQuery.Firstname, ColdFusion automatically converts it to the first row in the column. For example,
the following lines print the word "ben":
<cfset myCol = myQuery.Firstname >
<cfoutput>#mycol#</cfoutput>
But the following lines display an error message:
<cfset myCol = myQuery.Firstname >
<cfoutput>#mycol[1]#</cfoutput><br>
If you reference
Query["Firstname"]
For example, the following line results in an error message indicating that ColdFusion cannot convert a complex type
to a simple value:
<cfoutput> #myQuery['Firstname']# </cfoutput><br>
Similarly, the following lines print the name "marjorie", the value of the second row in the column:
<cfset myCol = myQuery["Firstname"]>
<cfoutput>#mycol[2]#</cfoutput><br>
However, when you make an assignment that requires a simple value, ColdFusion automatically converts the query
column to the value of the first row. For example, the following lines display the name "ben" twice:
<cfoutput> #myQuery.Firstname# </cfoutput><br>
<cfset myVar= myQuery['Firstname']>
<cfoutput> #myVar# </cfoutput><br>
Using periods in variable references
ColdFusion uses the period (.) to separate elements of a complex variable such as a structure, query, XML document
object, or external object, as in MyStruct.KeyName. A period also separates a variable scope identifier from the variable
name, as in Variables.myVariable or CGI.HTTP_COOKIE.
With the exception of Cookie and Client scope variables, which must always be simple variable types, you cannot
normally include periods in simple variable names. However, ColdFusion makes some exceptions that accommodate
legacy and third-party code that does not conform to this requirement.
For more information, see
"About
and
WDDX" on page 1058.
Understanding variables and periods
The following descriptions use a sample variable named MyVar.a.b to explain how ColdFusion uses periods when
getting and setting the variable value.
Getting a variable
ColdFusion can correctly get variable values even if the variable name includes a period. For example, the following
set of steps shows how ColdFusion gets MyVar.a.b, as in
Looks for myVar in an internal table of names (the symbol table).
1
2
If myVar is the name of a complex object, including a scope, looks for an element named
If myVar is not the name of a complex object, checks whether myVar.a is the name of a complex object and skips
step 3.
, ColdFusion does not automatically convert it to the first row of the column.
scopes" on page 56,
"Using Arrays and
<cfset Var2 = myVar.a.b>
Last updated 8/5/2010
Structures" on page 82, and
or
IsDefined(myVar.a.b
in the object.
a
49
"Using XML
):

Advertisement

Table of Contents
loading

Table of Contents