4 Replies Latest reply on Jan 27, 2016 7:05 AM by Birdwing

    ArrayAppend Bug


      Hello Everyone,


      I am the webmaster for a school district, and we have a system where parents enter the name of their street and the city they live in.

      The system then returns which schools their children will go to based on their address.


      We are running ColdFusion 11 and I recently installed Update 7.

      After this update was installed this system stopped working properly.

      Instead of returning unique entries, it returns the same entry multiple times.


      I did some testing and found that when using ArrayAppend() to add a Structure to an array, that it overwrites all of the entries in the Array to match the entry it just added.


      here is a section of my code

      <cfset StreetArray = ArrayNew(1)>
      <cfloop query="Streets">
          <cfset StreetRow['Street'] = STREET_NAME>
          <cfset StreetRow['Range'] = LOW_RANGE & ' - ' & HIGH_RANGE>
          <cfif EVEN_ODD is "E">
                <cfset StreetRow['EvenOdd'] = "Even">
          <cfelseif EVEN_ODD is "O">
                <cfset StreetRow['EvenOdd'] = "Odd">
                <cfset StreetRow['EvenOdd'] = "Both">
          <cfset StreetRow['City'] = Streets.CITY>
          <cfset StreetRow['Zip'] = ZIP>
          <cfset StreetRow['Elementary'] = ELEMENTARY_SCHOOL>
          <cfset StreetRow['Middle'] = MIDDLE_SCHOOL>
          <cfset StreetRow['High'] = HIGH_SCHOOL>
          <cfset ArrayAppend(StreetArray, StreetRow)>
          <cfdump var="#StreetRow#">
          <cfdump var="#StreetArray#">


      Now i added the cfdumps on the end for testing.Here is what I get after the dumps.


      As you can see the StreetRow variable is updating properly, but after the second ArrayAppend() both entries in the array are the same even though the array was correct the first time.


      I would like to also note that this does not happen if I explicitly create the structure inside the ArrayAppend() function so:

      <cfset ArrayAppend(StreetArray, {Street=STREET_NAME,Range=LOW_RANGE & ' - ' & HIGH_RANGE, City=Streets.CITY,Zip=ZIP,Elementary=ELEMENTARY_SCHOOL,Middle=MIDDLE_SCHOOL,High=HIGH_SCH OOL,EvenOdd=EvenOdd})>


      does not create the same issue.


      This appears to be some kind of Bug, unless I am missing something...

      It looks like ColdFusion is waiting until the loop is done before calling ArrayAppend() for all the loops. This works fine if you explicitly create the structures inside the function, but not so much if you are using a variable.