Just a little clueless... using Coldfusion8, if I dump my session to file:
<cfdump output="D:\ColdFusion8\logs\dump.txt" var="#Session#">
this includes:
accounttyp: whatever
I get the same result if I only dump this parameter:
<cfdump output="D:\ColdFusion8\logs\dump.txt" var="#Session.accounttyp#">
Question:
If it's defined and dump-able, how come checking isDefined like so:
<cfdump output="D:\ColdFusion8\logs\dump.txt" var="#IsDefined(Session.accounttyp)#">
turns out to be NO? If it's there it should be defined, shouldn't it?
Thanks for some clarification.
It is because the syntax is incorrect.
IsDefined
expects the name of a variable ie a string. By omitting the quotes around the variable name, the session variable gets evaluated first, and its value ("whatever") is what gets passed intoIsDefined
. So the code is actually checking for a variable named "whatever", not "session.accounttyp" ie:That is why the result is
NO
. This is the correct syntax. (Notice the quotes and lack of pound signs).However, I would suggest switching to
structKeyExists
. It is generally preferred overIsDefined
because it is more precise.This returns a boolean value:
So, you are asking it to return yes or no.
A better test might be this: