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>
<cfset StructDelete(Variables, "myVar") />
Variables
is the default scope for most variables in most contexts.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With