0

Arguments and Vars want their own name!

ColdFusion

As ColdFusion is scope based its possible to have a form, request and session variable with the same name. I would advise against this wherever possible as it can make debugging very confusing. Arguments and var scopes can not, however, share the same name. And when they do the (somewhat confusing) error will appear:

Cannot declare local variable userID twice.

Local variables cannot have the same names as parameters or other local variables.

 

The fix is rather simple simply change the name of the argument or the var!

Here is the code that gives the above error:


tags:
ColdFusion
 
Oddly enough I just experienced this for the first time last week. What really shocked me was not the behavior, but rather the fact that I had never done that before!
 
posted 960 days ago
Add Comment Reply to: this comment OR this thread
 
Allen said:
 
Are you sure this is an issue? I would think as long as your scoping your variables the argument scope would contain the argument and the other would be in a local scope. That is, I would think would solve the issue.
 
posted 960 days ago
Add Comment Reply to: this comment OR this thread
 
 
@Dave Ha.

@Allen Try it. You'll get the same error Dave and I got.
 
posted 960 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Twitter
You should follow me on Twitter here
About Me
I am a 34-year old Web Developer specializing in ColdFusion. I live and work in downtown Washington, DC with my wife and two daughters. Read more About Me

2007 CFeMmy Best Newcommer winner
As voted on by fellow CF Bloggers.
CFinNC - Carolina ColdFusion / Flex / Air Conference - Oct 17-18, 2009