Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to undefine a variable in ColdFusion?

Is it possible to undefine a variable in ColdFusion?

For example, something like this:

<cfset myVar = "lsajflksd" />
<cfoutput>
  <p>myVar is Defined? #IsDefined("myVar")#</p> <!--- Prints YES --->
</cfoutput>
<cfset Undefine(myVar) /> <!--- Doesn't exist... --->
<cfoutput>
  <p>myVar is Defined? #IsDefined("myVar")#</p> <!--- I want it to print NO --->
</cfoutput>
like image 872
Kip Avatar asked Jul 09 '09 16:07

Kip


2 Answers

<cfset StructDelete(Variables, "myVar") />

Variables is the default scope for most variables in most contexts.

like image 65
yfeldblum Avatar answered Sep 16 '22 22:09

yfeldblum


In modern versions, you can also use the struct.delete() member function.

myVar = "lsajflksd";

variables.delete('myVar');

https://docs.lucee.org/reference/objects/struct/delete.html

like image 26
Morg Denn Avatar answered Sep 20 '22 22:09

Morg Denn