Adobe COLDFUSION 9 Manual page 56

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
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" on page 93. 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
• 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">
Data type conversion
ColdFusion automatically converts between data types to satisfy the requirements of an expression's operations,
including a function's argument requirements. As a result, you generally don't need to be concerned about
compatibility between data types and the conversions from one data type to another. However, understanding how
ColdFusion evaluates data values and converts data between types can help you prevent errors and create code more
effectively.
Operation-driven evaluation
Conventional programming languages enforce strict rules about mixing objects of different types in expressions. For
example, in a language such as C++ or Basic, the expression
operator requires two numeric operands and "8" is a string. When you program in such languages, you must convert
between data types to ensure error-free program execution. For example, the previous expression might have to be
written as
(ToNumber("8") * 10)
In ColdFusion, however, the expression
ColdFusion processes the multiplication operator, it automatically attempts to convert its operands to numbers. Since
"8" can be successfully converted to the number 8, the expression evaluates to 80.
"About
scopes" on page 56.
("8" * 10)
.
evaluates to the number 80 without generating an error. When
("8" * 10)
Last updated 8/5/2010
produces an error because the multiplication
51

Advertisement

Table of Contents
loading

Table of Contents