Should I use cfreturn in a function with returntype void
Asked Answered
O

1

7

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>
Omer answered 23/4, 2013 at 9:0 Comment(0)
K
20

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.

Kaylakayle answered 23/4, 2013 at 9:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.