devbox@COMPUTEC The Computec development blog

9Sep/091

FYI: Function returning Void kills Variables

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.

Comments (1) Trackbacks (0)

Leave a comment

(required)

No trackbacks yet.