IsDefined

Description

Evaluates a string value to determine whether the variable named in it exists.

This function is an alternative to the ParameterExists function, which is deprecated.

Return value

True, if the variable is found, or, for a structure, if its key is defined; False, otherwise.

Returns False for an array or structure element referenced using bracket notation. For example, IsDefined("myArray[3]") always returns False, even if the array element myArray[3] has a value.

Category

Decision functions

Syntax

IsDefined("variable_name") 

See also

Evaluate

History

New in ColdFusion MX: this function can process only the following constructs:

Parameters

Parameter Description
variable_name
String, enclosed in quotation marks. Name of variable to test for.

Usage

When working with the URL and Form scopes, which are structures, the StructKeyExists function can sometimes be used in place of this function. The following blocks of code are equivalent:

Example

<h3>IsDefined Example</h3>

<cfif IsDefined("FORM.myString")>
<p>Because the variable FORM.myString is defined, we can show its contents. 
This lets us put a FORM and its resulting action page in the same page,
while using IsDefined to control the flow of page execution.
<p>The value of "FORM.myString" is <B><I><cfoutput>#FORM.myString#
 </cfoutput></I></B>
<cfelse>
<p>During the first execution of this page, the variable "FORM.myString" is 
not yet defined, so it is not evaluated.
</cfif>
...

Comments