[thelist] Problem with coldfusion and undefined vars

Joshua Olson joshua at waetech.com
Sat May 18 23:58:01 CDT 2002

----- Original Message -----
From: "Cameron McCormick" <lordcutter at telocity.com>
To: <thelist at lists.evolt.org>
Sent: Sunday, May 19, 2002 12:45 AM
Subject: [thelist] Problem with coldfusion and undefined vars

> Hi,
> I have a problem where when I check for a var that may or may not be set
> it returns an error.
> I tried making a <cfif isdefined(varname)>something to do with
> var</cfif> but it gives the same error that is isnt defined - why have
> isdefined if it wont accept it?
> I am a newbie to CF, so any advice is appreciated.
> thanks,
> Cameron

With isdefined, make sure that you are passing the variable name as a
string.  For example:

<cfif isdefined("varname")>something</cfif>

Make sure the string literal is actually the name of the variable.

Some people prefer not to use isdefined at all.  Another approach is to use
cfparam, such as this.

<cfparam name="varname" default="some known value">
<cfif varname IS "some known value">
  do something

A downside to doing this is that CF must actually allocate memory for the
variable even if you don't plan on using it.  Jeff will probably argue
adamantly that IsDefined is pure evil for any number of reasons.  But, if
IsDefined works for you, go with it.


More information about the thelist mailing list