Avoid use of scope names for argument names

This falls under the category of “I knew better…” I’m working with a client who is using my YouTube CFC product. They were encountering some problems and wanted me to work on modifications to their page to handle cases where YouTube was down, or simply not returning proper information for whatever reason. (In our case it ended up being a network issues. ColdFusion couldn’t hit any remote site due to a network change.) While working on the development server I made this simple change to my CFC:

<cfif not isXML(result.fileContent) or isDefined("url.xxx")>

This would let me quickly toggle back and forth between a good connection and a forced YouTube breakdown. But something odd happened.

When I added ?xxx=1 to my URL, the error condition didn’t fire. I checked to ensure I wasn’t caching, reuploaded, etc, and nothing worked.

Turns out I had used URL for the name of one of the arguments to the function:

<cfargument name="url" type="string" required="true">

I typically avoid doing this. All I can think of in this case I figured since I always use “arguments.” when referencing arguments, there wouldn’t be any confusion. But that wasn’t the case. As soon as you add an argument like this, you essentially “break” the URL scope. (Switching to structKeyExists didn’t help.)

I renamed my argument to “theurl” and then everything worked fine.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. 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 https://www.raymondcamden.com

Comments