Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use cfreturn in a function with returntype void

What would be the correct way? I think both work, but I wonder if there are benefits from one to the other.

<CFFUNCTION name="setSomething" access="public" output="no" returntype="void">
    <CFSET ... />
</CFFUNCTION>

OR

<CFFUNCTION name="setSomething" access="public" output="no" returntype="void">
    <CFSET ... />

    <CFRETURN />
</CFFUNCTION>
like image 402
Seybsen Avatar asked Apr 23 '13 09:04

Seybsen


1 Answers

It doesn't make much of a difference. There is no right or wrong here. When the return type has been set to void the function can't return anything.

You can use <cfreturn /> within your code to prematurely exit your function, if you need to. Putting it at the end won't do anything, because the function will return nothing whether you put it there or not. But it also doesn't hurt to put it there and some people might think it more clear if it's there to state "nothing is been returned here".

I think it's a matter of personal preference.

like image 115
Till Helge Avatar answered Nov 06 '22 04:11

Till Helge