title: What is the scope evaluation order in ColdFusion when setting a variable?
body: <p>The scope evaluation order is well known/documented when <a href="http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec09af4-7fdf.html" rel="nofollow noreferrer">using variables</a>.  However I can't find any information about the scope evaluation order when setting a variable.</p>
  
  <p>One would presume it's the same list, but there appears to be a few caveats as demonstrated here:</p>
  
  <pre><code>&lt;cfset qryChain = queryNew("id,next")&gt;
  &lt;!--- add some data so the cfloop kicks in ---&gt;
  &lt;cfloop query="qryChain"&gt;
      &lt;cfset Next = StructNew()&gt;
      &lt;cfset Next.id = qryChain.next&gt;
  &lt;/cfloop&gt;
  </code></pre>
  
  <p>The above code is trying to reuse a variable name that it shouldn't, but fails in an unexpected way.  </p>
  
  <p>Since the <code>cfset</code>s are inside a query loop, item 4 of the scope evaluation order should be used for both. Instead <code>Next</code> is being evaluated as <code>Variables.Next</code> (item 6), and then <code>Next.id</code> is being evaluated as <code>Variables.qryChain.next.id</code> (item 4) and fails.</p>
  
  <p>Is this documented anywhere?  Is it simply items 1-6 of the "using" list above with a few caveats?  Are these caveats intentional, or bugs?  What other caveats are there?</p>