-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> > Figured it out (taken me months!)
> >
> > I need to put quotes in, which seems a bit irish to me as all
> > other functions (those I can think of off the top of my head) you
> don't put the
> > quotes in when putting in a variable.
It actually makes perfect sense when you think about that IsDefined
is doing.
For most CF Functions (let's look at DollarFormat), you're passing a
variable that is to be operated on. So for DollarFormat, you could
say:
DollarFormat(ThisVar) or
DollarFormat("1.50") or even
DollarFormat("#ThisVar#")
The first one means "Take the value that's stored in ThisVar and
operate on it."
The second one & third ones mean "Take the value represented by this
string and operate on it" except that in number three, the poundsigns
in the string force an evaluation of what is in ThisVar & fill the
string with that value before sending it to DollarFormat.
Now... For a function like IsDefined, the correct syntax:
IsDefined("ThisVar")
means "look for a variable named by this string (ThisVar) and tell me
if it exists."
When you leave out the quotes:
IsDefined(ThisVar)
IsDefined("#ThisVar#") <!--- This means the same thing --->
you're saying "take the contents of the variable ThisVar and tell me
if there's a variable with that name."
In the incorrect version, you're telling ColdFusion to evaluate the
variable ThisVar (which fails if it's not defined) and then operate
on the value of that variable. In the correct version, CF takes
looks for a variable named by the string value that you pass it.
Here's an example that won't cause an error, but clearly won't do
what you want it to:
<cfset ThisVar = "Booga">
<cfif IsDefined(ThisVar)>
You'll never see this.
<cfelse>
You WILL see this since there's no variable named Booga in this
template
</cfif>
Another interesting example"
<cfset ThisVar = "ThisVar">
<cfif IsDefined(ThisVar)>
You'll see this since there is a variable named ThisVar
<cfelse>
You won't see this.
</cfif>
So... Does that help to clear up the mysterious quirks of IsDefined?
Best regards,
Zac Bedell
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>
Comment: Please use PGP!!!
iQA/AwUBOaVfrQraVoMWBwRBEQI+2ACeIcOdgOrPpFlSxVg+q8VNFU0t4R4AoJ03
RFIZGScAz85fZwa9sP80EAkL
=9IAa
-----END PGP SIGNATURE-----
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.