tracker issue : CF-3037072

select a category, or use search below
(searches all categories and all time range)
Title:

Bug 74323:In CF9, a LOCAL-scope variable can overwrite an ARGUMENT-scope variable having the same name

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Aaron Neff / Aaron Neff (Aaron Neff)

Created: 12/16/2008

Components: Language

Versions: 9.0

Failure Type: Unspecified

Found In Build/Fixed In Build: 0000 / 220525

Priority/Frequency: Major / Unknown

Locale/System: English / Win All

Vote Count: 1

Problem:

In CF9, a LOCAL-scope variable can overwrite an ARGUMENT-scope variable having the same name.  This behavior differs from CF8.

Forum thread here: https://prerelease.adobe.com/project/forum/thread.html?cap=87529BDA13744B3DB718E841890B9240&forid={A8760B70-42A5-45FC-8BA2-DFCF173A9580}&topid={3CC148C6-D952-403D-9EC9-741120B5D654}
Method:

In the following example, CF8 returns '1' while CF9 returns '0':

<cffunction name="myFunction" access="public" output="no">
  <cfargument name="id" type="numeric" default="1" />
  <cfscript>
    var local={};
    local.id = 0;
  </cfscript>
  <cfreturn ARGUMENTS.id />
</cffunction>
<cfdump var="#myFunction()#" />

Also, Sean made a good observation - please see the 1st reply in this thread: https://prerelease.adobe.com/project/forum/thread.html?cap=87529BDA13744B3DB718E841890B9240&forid={A8760B70-42A5-45FC-8BA2-DFCF173A9580}&topid={3CC148C6-D952-403D-9EC9-741120B5D654}

It mentions how the following is now legal in CF9: (the 'Cannot declare local variable id twice.' error is not thrown)

<cffunction name="myFunction" access="public" output="no">
  <cfargument name="id" type="numeric" default="1" />
  <cfscript>
    var id = 0;
  </cfscript>
  <cfreturn ARGUMENTS.id />
</cffunction>
<cfdump var="#myFunction()#" />

I also agree that this would break some code.

I'm rating the severity as '3/High' (at minimum) b/c I feel that if a new feature can break code in this manner, then it should not be rated as 'Easy Workaround'.
Result:

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3037072

External Customer Info:
External Company:  
External Customer Name: Aaron Neff
External Customer Email: 3D1D17B03C844EBF992001AC
External Test Config: 12/16/2008

Attachments:

Comments:

I think the first issue will break some existing code. Users that create their own "local" pseudo-scope will expect to be able to have local.somevar be distinct from arguments.somevar. The second example will confuse users who accidentally declare a local variable matching an argument name - and then find they are one and the same variable. One solution would seem to be for LOCAL scope (and therefore VAR-declared variables) to be a distinct scope from ARGUMENTS scope. Another solution might be to use VAR as the name of the new local scope (less likely to conflict with existing code) and to disallow the VAR declaration to have the same name as an ARGUMENTS scope name.
Vote by External U.
24391 | November 10, 2011 07:08:42 PM GMT