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

  • Home
  • SEARCH
  • 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 7721173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:51:25+00:00 2026-06-01T03:51:25+00:00

I’m using Coldfusion MX 8. I recently had a situation where variables seem to

  • 0

I’m using Coldfusion MX 8. I recently had a situation where variables seem to be “swapping” between sessions. I found some information regarding entire sessions swapping, but this was not the case. It was just one variable being swapped, not the entire session. My code snippets follow:

var idArray = ListToArray(arguments.event.getArg("itemIDs"));
var oItemDetail = 0;
var oItem = 0; //Inserting this line seems to have fixed the error.
var i = 0;

for (i=1;i lte ArrayLen(idArray);i=i+1) {

    //Log Spot #1 – cflog idArray[i] and arguments.event.getArg("statusNotes")

    oItem = getItemService().getItem(idArray[i]);
    oItemDetail = getItemService().getItemDetail();
    oItemDetail.setItemID(oItem.getItemID());

    oItemDetail.setStatusNotes(arguments.event.getArg("statusNotes"));

    getItemService().saveItem(oItem);
    getItemService().saveItemDetail(oItemDetail);
}

//getItem and getItemDetail just call getTransfer().get()
//saveItem and saveItemDetail just call getTransfer().save()

For example, at Log Spot #1, idArray[i] might have been “1”, and the StatusNotes event arg might be “abc”.

But should another person, in another session, using another login, in another place, another browser, etc.etc. Use the function at exactly the same time, using idArray[i] = “2” and statusNotes = “def”, then Item Detail “abc” might instead attach to Item “2”, and Item Detail “def” attach to Item “1”.

The fact that, at Log Spot #1, the variables logged are correct, but in the database they are swapped, points to these lines of code as the suspects.

This problem has gone away by declaring “var oItem” at the top.

So I guess I’m a little shocked by this revelation. I would assume that not declaring my local variables would mean another variable, with the same name, in another function, but in the same session might get overwritten. But this seems to be some sort of internal memory issue. The variables are not even being overwritten, rather swapped, between sessions!

I was wondering if anyone had any similar experiences and could shed some light on this?

  • 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-06-01T03:51:27+00:00Added an answer on June 1, 2026 at 3:51 am

    Unvar’d variables are made private variables within the object that they are contained in. Which causes two problems,

    1. They are shared (accessed and written to) by functions (within that same component)
    2. They live beyond the life of the function call

    When you var a variable it makes it a local variable only to that function. Only that function can use it and it only lives as long as that function does.

    In your case, this problem doesn’t really have anything to do with sessions, other than that is the persistent scope where you happen to be storing the data from these functions.

    You said

    I would assume that not declaring my local variables would mean another variable, with the same name, in another function, but in the same session might get overwritten.

    But it would be more accurate to say

    I would assume that not declaring my local variables would mean another variable, with the same name, in another function, but in the same OBJECT might get overwritten.

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

Sidebar

Related Questions

I am using ColdFusion 9.1.2 We are using a CFC to save some data
I'm using ColdFusion MX7 to perform a CFEXECUTE on some Java 6 code. Unfortunately,
I am using ColdFusion 8 and 9. I was reading some ColdFusion best practices
I have been using plain forms and input fields in coldfusion for some time
I am using ColdFusion 9.0.1 I recently read that in ColdFusion 9, it is
I am using ColdFusion 9.0.1 and some database that I cannot change. I am
I'm using ColdFusion to populate a template that includes HTML unordered lists ( <ul>
I'm using ColdFusion to return a result set from a SQL database and turn
We are using ColdFusion MX7. The CFDOCUMENT tag uses iText for the PDF creation
I'm using coldfusion 9 and I'm trying to grab a file from an ftp

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.