23.08.2013 Views

ColdFusion Developer's Guide - Electromanuals.org

ColdFusion Developer's Guide - Electromanuals.org

ColdFusion Developer's Guide - Electromanuals.org

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Ofrecido por www.electromanuales.com<br />

<br />

#mycol[2]#<br />

ADOBE COLDFUSION 8<br />

<strong>ColdFusion</strong> Developer’s <strong>Guide</strong><br />

However, when you make an assignment that requires a simple value, <strong>ColdFusion</strong> automatically converts the query<br />

column to the value of the first row. For example, the following lines display the name "ben" twice:<br />

#myQuery.Firstname# <br />

<br />

#myVar# <br />

Using periods in variable references<br />

<strong>ColdFusion</strong> uses the period (.) to separate elements of a complex variable such as a structure, query, XML document<br />

object, or external object, as in MyStruct.KeyName. A period also separates a variable scope identifier from the<br />

variable name, as in Variables.myVariable or CGI.HTTP_COOKIE.<br />

With the exception of Cookie and Client scope variables, which must always be simple variable types, you cannot<br />

normally include periods in simple variable names. However, <strong>ColdFusion</strong> makes some exceptions that accommodate<br />

legacy and third-party code that does not conform to this requirement.<br />

For more information, see “About scopes” on page 42, “Using Arrays and Structures” on page 68, and “Using XML<br />

and WDDX” on page 865.<br />

Understanding variables and periods<br />

The following descriptions use a sample variable named MyVar.a.b to explain how <strong>ColdFusion</strong> uses periods when<br />

getting and setting the variable value.<br />

Getting a variable<br />

<strong>ColdFusion</strong> can correctly get variable values even if the variable name includes a period. For example, the following<br />

set of steps shows how <strong>ColdFusion</strong> gets MyVar.a.b, as in or IsDefined(myVar.a.b):<br />

1 Looks for myVar in an internal table of names (the symbol table).<br />

2 If myVar is the name of a complex object, including a scope, looks for an element named a in the object.<br />

If myVar is not the name of a complex object, checks whether myVar.a is the name of a complex object and skips<br />

step 3.<br />

3 If myVar is the name of a complex object, checks whether a is a complex object.<br />

4 If a or myVar.a is the name of a complex object, checks whether b is the name of a simple variable, and returns<br />

the value of b.<br />

If myVar is a complex object but a is not a complex object, checks whether a.b is the name of a simple variable<br />

and returns its value.<br />

If myVar.a is not a complex object, checks whether myVar.a.b is the name of a simple variable and returns its<br />

value.<br />

This way, <strong>ColdFusion</strong> correctly resolves the variable name and can get its value.<br />

You can also use array notation to get a simple variable with a name that includes periods. In this form of array<br />

notation, you use the scope name (or the complex variable that contains the simple variable) as the “array” name.<br />

You put the simple variable name, in single- or double-quotation marks, inside the square brackets.<br />

35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!