Variables in CFML; Dot Notation

Dot notation is generally simpler to write and understand, but not as flexible as Indexed notation (described next). With Dot notation each level, or container of the variable is separated by a period, or "dot". We've already seen Dot notation in action in our initial discussion of variable scopes:

Form.FieldName
URL.Foo
CGI.SCRIPT_NAME

These examples represent the simplest form of dot notation a single "parent" (in this case the scope) and "child" (the variable). Dot notation can, however, be arbitrarily deep with many parents depending on the complexity of the nested object you're referencing. The rightmost item in Dot notation is the variable or container that you wish to reference.

Dot notation is applicable to the data types "Query" and "Structure" (and to component objects which are treated as structures by ColdFusion).

Queries

Using Dot notation for referencing queries takes the form queryname.columnname. This is the most common way of accessing query data. By default this simple notation will return the data from the first row of the specified column.

Queries, like all other variables are also part of a scope. So, for example, you may decide to create the query "myQuery" in the "Request" scope. This query has a column named "ColOne" and that column could be accessed as Request.myQuery.ColOne

Structures

Referencing values in a structure with Dot notation takes the form StructName.KeyName. Structures can, of course, hold other Structure structures (or any other data type) as values. This creates a nested structure which can be accessed by describing the nesting in your Dot notation. For example:

MyMainStruct.MySubStruct.KeyName
MyMainStruct.MySubStruct.MyOtherSubStruct.KeyName
MyMainStruct.MySubStruct

In these examples the first two would return the values contained in those keys while the last would return a pointer (see Assignment by Value and Reference for a discussion on assignment by reference and pointers) to the structure indicated. Of course structures, like queries are also always members of a scope. If "MyMainStruct" was part of the "Session" scope you access the first example as Session.MyMainStruct.MySubStruct.KeyName.

12 Current Sessions; Time: 23:04:17 06-01-2009; Tick: 453