Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7606835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:30:31+00:00 2026-05-31T00:30:31+00:00

The scope evaluation order is well known/documented when using variables . However I can’t

  • 0

The scope evaluation order is well known/documented when using variables. However I can’t find any information about the scope evaluation order when setting a variable.

One would presume it’s the same list, but there appears to be a few caveats as demonstrated here:

<cfset qryChain = queryNew("id,next")>
<!--- add some data so the cfloop kicks in --->
<cfloop query="qryChain">
    <cfset Next = StructNew()>
    <cfset Next.id = qryChain.next>
</cfloop>

The above code is trying to reuse a variable name that it shouldn’t, but fails in an unexpected way.

Since the cfsets are inside a query loop, item 4 of the scope evaluation order should be used for both. Instead Next is being evaluated as Variables.Next (item 6), and then Next.id is being evaluated as Variables.qryChain.next.id (item 4) and fails.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:30:32+00:00Added an answer on May 31, 2026 at 12:30 am

    Scope evaluation during assigment

    I am aware of two different methods of scope evaluation when creating variables in ColdFusion. I haven’t tested every possible instance, but this is how it should work.

    The first instance uses the full list of scopes in evaluating unscoped variables. This is used by cfparam when creating variables. If ColdFusion does not find a variable with the given name then it will create it in the Variables scope.

    The second instance uses the first 6 scopes in evaluating unscoped variables and then if unsuccessful will also create the variable in the Variables scope. This is employed by cfset and any other tags that creates variables, such as cfhttp with the result attribute, and cfsavecontents variable attribute.

    As you observed there is the odd “sometimes ignore” the query scope issue. I would classify that as a bug, but someone may yet be able to provide a reason why the exception needs to be made.

    Hoisting

    Although ColdFusion was designed to copy JavaScript in a lot of ways (specifically cfscript) there is a subtle deviation which I haven’t seen documented. With regard to functions (both script and tag), JavaScript employs hoisting, whereas ColdFusion does not.

    Hoisting is the process of automatically moving the declaration of a variable to the top of the function, while maintaining the code placement of the assignment of the variable. The means that the scope of a variable will not change in JavaScript, but it can in ColdFusion.

    Prior to CF9 the var keyword had to be used at the top of the function, essentially negating the need for hoisting. This is different from JavaScript, where var can be used anywhere in a function and employs hoisting. With CF9 ColdFusion adopted the declare anywhere philosophy, but neglected to implement hoisting.

    In both the following examples JavaScript would only be dealing with a single scope, with x being function local.

    <!--- sets variables in 1 scope --->
    <cfscript>
        var x = 0;
        x = 1;
        local.x = 7;
    </cfscript>
    

    Compared to:

    <!--- sets variables in 2 scopes --->
    <cfscript>
        x = 1;
        var x = 0;
        local.x = 7;
    </cfscript>
    

    To avoid the potential pitfalls created by the lack of hoisting you can either var only at the top of the function, or do things as many have prior to CF9 and declare a var structure at the top of the function and prefix all variables with that (remembering to not name it local). e.g.

    <cfset var localVars = StructNew()>
    <cfset localVars.x = 7>
    <cfset localVars.y = 1>
    

    var vs local

    In functions var appears to be a second class citizen to the local scope. If you try to set a local variable to the same name as an argument using var you will receive an error message saying Use local to define a local variable with same name. despite var and local supposedly being equivalent.

    More

    There may be additional caveats and bugs, however I’m not aware of there being any documented cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scope: PHP-mysql based site, using memcached. Caching issue is mostly about prices. Because of
What is the scope of variables in javascript? Do they have the same scope
Within the scope of a Rails controller or a view: How can I query
I have an scope bar containing a NSSearchField. The bar can be shown and
All of the continuation tutorials I can find are on fixed length continuations(i.e. the
Scope : - using overriden ArrayAdapter; - using selector; - using isEnabled for disabling
using (TransactionScope scope = new TransactionScope()) using (var context = new dwfEntities()) { var
I'm running into some type of a scope issue that's preventing instance variables from
The following has unspecified results because evaluation order is unspecified: std::string f() { std::cout
Scope: Using Google Test and OpenCV. I'd like to test that my Vec3f equals

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.