My experience has always been that inside a cfloop on a query, you
must specify the scope. Inside a cfoutput on query you do not need to
specify the scope.

Cheers,
Kris


> I believe this behavior is as expected, however it breaks our code that 
> worked in CF 8. Similar issues have been discussed here and maybe even raised 
> on the bug tracker, but I didn't see an example quite like this, so I wanted 
> to share.
>
> Basically, when in a function (where local scope is automatically created) 
> and looping over a query or a list, you may reference a column name or the 
> list index without adding a scope. For example, myQuery has a column named 
> "key."
>
> <cfloop query="arguments.myQuery">
>  <cfset local.key = key>
> </cfloop>
>
> On the first iteration through the loop, the variable local.key does not 
> exist. The column "key" is found in the query, and now local.key equals that 
> value; say it is 1. On the next loop iteration, CF sees that local.key indeed 
> does exist and never looks to the query for the column "key". The scope 
> hierarchy looks in LOCAL before it looks to the query we are looping over. So 
> each subsequent assignment of local.key will equal 1.
>
> There are several fairly simple workarounds: don't use the same variable name 
> for the local scope; scope the right side of the assignment; etc. The point 
> is you will need to watch out for this on legacy code if you're upgrading to 
> ColdFusion 9.
>
> I don't think this should be filed as a bug, although the current scope 
> hierarchy could be debated. That is why I'm posting here and on my blog which 
> also has sample code for download:
> http://www.mattjanell.com/index.cfm?event=showEntry&entryId=B5EBBF4F-0C02-AEAF-607ECCAD91A37089

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:333875
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to