tbaum
asked on
How do I undefine a variable in CF 5.0?
How can I completely remove/annihilate/undefine a defined variable that would cause it to then fail an 'IsDefined()' test?
Example:
<cfset Application.TempVar = "test">
<!--- do what? to cause this if test to fail? --->
<cfif IsDefined( "Application.TempVar" )>
<cfoutput>OK</cfoutput>
<cfelse>
<!--- want to wind up HERE --->
<cfoutput>but I thought it existed!</cfoutput>
</cfif>
Remember, CF5! Thanks!
Example:
<cfset Application.TempVar = "test">
<!--- do what? to cause this if test to fail? --->
<cfif IsDefined( "Application.TempVar" )>
<cfoutput>OK</cfoutput>
<cfelse>
<!--- want to wind up HERE --->
<cfoutput>but I thought it existed!</cfoutput>
</cfif>
Remember, CF5! Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mosphat, GOOD ANSWER, now do me one better...
You will get the points, now for the bonus round...
That will work find for Application and Session vars, but what about just plan-old local vars? How would you go about destroying them?
Thanks.
You will get the points, now for the bonus round...
That will work find for Application and Session vars, but what about just plan-old local vars? How would you go about destroying them?
Thanks.
Like I said: even if you don't define a scope, it ends up in the variables scope.
This variable is actually set in the variables scope:
<cfset plain_old_local_var = "test">
So you can delete it like this:
<cfset structDelete(variables, "plain_old_local_var")>
This variable is actually set in the variables scope:
<cfset plain_old_local_var = "test">
So you can delete it like this:
<cfset structDelete(variables, "plain_old_local_var")>
<CFIF IsDefined( "Application.TempVar" )> AND Application.TempVar NEQ "">
or something to that affect