DevWebPro Newsletter:


Get Your Site Submitted for Free in the World's Largest B2B Directory!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions

Avoid Using Scope Names For Argument Names

By Raymond Camden
Expert Author
Article Date: 2007-11-16

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.

Comments

About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.


Newsletter Archive | Article Archive | Submit Article | Advertising Information | About Us | Contact | Site Map

Dev Web Pro is an iEntry, Inc.® publication - 1998-2008 All Rights Reserved Privacy Policy and Legal