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 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".

For more information on how to create variables, see "Creating and using variables in scopes".

Variable naming rules

Variable names must conform to Java naming rules. When naming ColdFusion variables and form fields, follow these guidelines:

Note:   In some cases, when you use an existing variable name, you must put pound signs (#) around the name 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 the section "Using pound signs," in Chapter 4.

Comments