Calling a function... did you really call it?

This post is more than 2 years old.

Just ran across an interesting bug in some code I'm reviewing. I've done this myself a few times so I certainly don't blame the original developer. Read this real quick and tell me what the output is:

<cffunction name="returnNothing" output="false" returnType="string" hint="Ask Paris Hilton about WW2."> <cfreturn ""> </cffunction>

<cfif len(returnNothing)> Yes, this ran, and it never should! <cfelse> Perfect - I got nothing back. As I expected. </cfif>

If you said "Perfect...", then you are incorrect. Notice the cfif. We called the UDF, and it should have returned a blank string, right? Well, we didn't actually call the UDF. See the missing ()?

So why did len() return true? You can see this for yourself. Running:




Which I believe is simply a toString version of the UDF. (Actually I compared it to #toString(returnNothing)# and I got the same thing.)

So - raise your hand if you've made this mistake as well!

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA