Status/Resolution/Reason: Closed/Fixed/
Reporter/Name(from Bugbase): Jork Zijlstra / Jork Zijlstra (Jork Zijlstra)
Created: 09/11/2012
Components: Language
Versions: 9.0.1
Failure Type:
Found In Build/Fixed In Build: 9.0.1 / 3328578
Priority/Frequency: Major / All users will encounter
Locale/System: English / Windows 7
Vote Count: 0
Problem Description:
When using cfloop array the index should contain the item in the array. When you var scope the index anywhere in your function the index item will always be the first item of the array.
I suspect that since array are nog passed by reference this is a scoping issue.
Steps to Reproduce:
Create a component with the folling:
<cfcomponent>
<cffunction name="test" returntype="void" access="public" output="false">
<cfset test_arr = ["aaa", "bbb"] />
<cfdump var="#test_arr#">
<cfloop array="#test_arr#" index="item_str">
<cfdump var="#item_str#">
</cfloop>
<!--- Put the next line in comment to have a working loop --->
<cfset var item_str = "" />
<cfabort>
</cffunction>
</cfcomponent>
And call the function test()
Actual Result:
2x times an output of "aaa" and "aaa"
Expected Result:
output of "aaa" and "bbb"
Any Workarounds:
1) Use cfscript with a for(item_str in test_arr)
2) Don't var scope the idex in the function when tag based is needed
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3328578
External Customer Info:
External Company:
External Customer Name: Jork Zijlstra
External Customer Email:
External Test Config: My Hardware and Environment details:
Windows 7, CF 9.0.1 multiserver
Attachments:
Comments: