Naming a ColdFusion variable beginning with a number
The naming rules for creating ColdFusion variables are found here in the LiveDocs. The first bullet point is
<cfset field = "00N30000000dqFd"> <!--- here is a variable that we assign a value starting with a number --->
<cfset 00N30000000dqFd = "test"> <!--- variable starting with number throws error: "00N30000000dqFd," on line 3, column 8, is not a valid identifer name. --->
<cfparam name="form.#field#" default=""> <!--- paraming "00N30000000dqFd" in the form scope is ok --->
<cfdump var="#form#" label="after param">
<cfset "form.#field#" = "new value"> <!--- doing this cfset method throws an error: The string "form.00N30000000dqFd" is not a valid ColdFusion variable name. --->
<cfset form["#field#"] = "1st value"> <!--- doing the structure method sets the variable ok --->
<cfdump var="#form#" label="after assigning">
<cfif IsDefined("form.#field#")> <!--- doing this IsDefined() method of checking if the variable exists in the Form scope throws an error: Parameter 1 of function IsDefined, which is now "form.00N30000000dqFd", must be a syntactically valid variable name.--->
<cfset "form.#field#" = "2nd value">
</cfif>
<cfif StructKeyExists(form,field)> <!--- doing this structure key check method is ok --->
<cfset form["#field#"] = "2nd value">
</cfif>
<cfdump var="#form#" label="end of demo">
CFDump output
after param - struct
00N30000000DQFD [empty string]
after assigning - struct
00N30000000DQFD 1st value
end of demo - struct
00N30000000DQFD 2nd value
- A variable name must begin with a letter, underscore, or Unicode currency symbol.
<cfset field = "00N30000000dqFd"> <!--- here is a variable that we assign a value starting with a number --->
<cfset 00N30000000dqFd = "test"> <!--- variable starting with number throws error: "00N30000000dqFd," on line 3, column 8, is not a valid identifer name. --->
<cfparam name="form.#field#" default=""> <!--- paraming "00N30000000dqFd" in the form scope is ok --->
<cfdump var="#form#" label="after param">
<cfset "form.#field#" = "new value"> <!--- doing this cfset method throws an error: The string "form.00N30000000dqFd" is not a valid ColdFusion variable name. --->
<cfset form["#field#"] = "1st value"> <!--- doing the structure method sets the variable ok --->
<cfdump var="#form#" label="after assigning">
<cfif IsDefined("form.#field#")> <!--- doing this IsDefined() method of checking if the variable exists in the Form scope throws an error: Parameter 1 of function IsDefined, which is now "form.00N30000000dqFd", must be a syntactically valid variable name.--->
<cfset "form.#field#" = "2nd value">
</cfif>
<cfif StructKeyExists(form,field)> <!--- doing this structure key check method is ok --->
<cfset form["#field#"] = "2nd value">
</cfif>
<cfdump var="#form#" label="end of demo">
CFDump output
after param - struct
00N30000000DQFD [empty string]
after assigning - struct
00N30000000DQFD 1st value
end of demo - struct
00N30000000DQFD 2nd value


<< Home