Adobe COLDFUSION 9 Manual page 44

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
• How to use variables correctly
Creating variables
You create most ColdFusion variables by assigning them values. (You must use the
arrays.) Most commonly, you create variables by using the
assignment statements in CFScript. Tags that create data objects also create variables. For example, the
creates a query object variable.
ColdFusion automatically creates some variables that provide information about the results of certain tags or
operations. ColdFusion also automatically generates variables in certain scopes, such as Client and Server. For
information on these special variables, see Reserved Words and Variables in the CFML Reference and the
documentation of the CFML tags that create these variables.
ColdFusion generates an error when it tries to use a variable before it is created. This can happen, for example, when
processing data from an incompletely filled form. To prevent such errors, test for the variable's existence before you
use it. For more information on testing for variable existence, see
For more information on how to create variables, see
Variable naming rules
ColdFusion variable names, including form field names and custom function and ColdFusion component argument
names, must conform to Java naming rules and the following guidelines:
• A variable name must begin with a letter, underscore, or Unicode currency symbol.
• The initial character can by followed by any number of letters, numbers, underscore characters, and Unicode
currency symbols.
• A variable name cannot contain spaces.
• A query result is a type of variable, so it overwrites a local variable with the same name.
• ColdFusion variables are not case sensitive. However, consistent capitalization makes the code easier to read.
• When creating a form with fields that are used in a query, match form field names with the corresponding database
field names.
• Periods separate the components of structure or object names. They also separate a variable scope from the variable
name. You cannot use periods in simple variable names, with the exception of variables in the Cookie and Client
scopes. For more information on using periods, see
The following rule applies to variable names, but does not apply to form field and argument names:
• Prefix each variable's name with its scope. Although some ColdFusion programmers do not use the Variables prefix
for local variable names, use prefixes for all other scopes. Using scope prefixes makes variable names clearer and
increases code efficiency. In many cases, you must prefix the scope. For more information, see
page 56.
Note: In some cases, when you use an existing variable name, you must enclose it with number signs (#) to allow
ColdFusion to distinguish it from string or HTML text, and to insert its value, as opposed to its name. For more
information, see
"Using number
cfset
"Creating and using variables in
"Using periods in variable
signs" on page 70.
Last updated 8/5/2010
ArrayNew
tag. You can also use the
cfparam
"Ensuring variable
existence" on page 61.
scopes" on page 58.
references" on page 49.
39
function to create
tag, and
tag
cfquery
"About
scopes" on

Advertisement

Table of Contents
loading

Table of Contents