9. September 2009 9:40 by Marc

FYI: Function returning Void kills Variables

9
Sep/09
1

I recently discovered some interesting behaviour in Coldfusion. If you ask for a result of a function in a variable and you set returntype void, the variable is destroyed and cant be found after this.

Example:

<cffunction name="getSomething" returntype="void">
 
     Do something here, like updating a database 
     or increasing a counter value
 
</cffunction>
 
<cfset VARIABLES.RecieveSomething = "">
 
<cfset VARIABLES.RecieveSomething= getSomeThing()>
 
<cfif IsDefined("VARIABLES.RecieveSomething")>
     still there
<cfelse>
     cant found this variable anymore
</cfif>

Returntype Void is kinda tricky, so use it well-considered.