
54
Chapter 3: Using ColdFusion Variables
Creating variables
You create most ColdFusion variables by assigning them values. (You must use the
ArrayNew
function to create arrays.) Most commonly, you create variables by using the
cfset
tag. You can
also use the
cfparam
tag, and assignment statements in CFScript. Tags that create data objects
also create variables. For example, the
cfquery
tag 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 Chapter 1, “Reserved
Words and Variables,” in
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
“Ensuring variable existence” on page 78
.
For more information on how to create variables, see
“Creating and using variables in scopes”
on page 75
.
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 cannot have the same name as another local variable in
the current ColdFusion application page.
•
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
“Using periods in variable references” on page 64
.
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, you should 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
“About scopes” on page 72
.
Note:
In some cases, when you use an existing variable name, you must enclose it with pound 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
Chapter 4, “Using pound signs,” on page 89
.
Содержание COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...