Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Local Variables 1

Status
Not open for further replies.

iao

Programmer
Feb 23, 2001
111
US
How does one go about completely removing a local variable?

For example, if I have the following:

<CFSET test1 = 1>

The output here will be &quot;1&quot;. Easy. Well, what if, somewhere in the logic, I need to completely remove this variable (not just reset it, but completely remove it). How do I go about doing this?

What seems silly to me is that in other instances, with other types of variables, I have used a StructDelete function. However, I have always used this function with variable types such as &quot;application&quot;, &quot;session&quot;, etc. Never before have I used &quot;Local&quot; as the variable type. Any ideas?
 
As far as I know, you can't totally destroy a local variable. I think you answered it yourself, but you can put it in a scope like request.test1 or something like that.

What I normally do is 2 things: Replace the value with something totally bogus and check for that bogus value:
e.g
<cfset test1 = &quot;SomethingTotallyBogusHere&quot;>
<cfif test1 is &quot;SomethingTotallyBobusHere&quot;>
Test 1 doesnt exist (sort of)
</cfif>

Or set it to a different type
<cfset test1 = &quot;StringNow&quot;>
<cfif NOT isNumeric(test1)>Isn't a number so doesnt exist, sort of</cfif>

Depending on your code, you might get around it by using a cfparam instead of cfset, but it may or may not work in your situation.

HTH,
Tim P.
 
CFDude

Thanks for your response. Yes, in a round about way, this was the way I had to tackle the problem.

So, I am guessing that there is just no way to kill a local variable.

Oh well. Thanks again for you help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top