Increment operator issue with ColdFusion 8 arrays

Posted on September 8, 2011 by Phil   no comments yet

I spent a good 30 mins debugging a module in one of our products that has been running fine in CF8 for a while but crashed when run on CF9 recently. The problem turned out to be a bug in my code but it also unveiled this freaky bug with CF8. It turns out that if you try to increment the value of a variable used as an array index when assigning a structure or array to that index using literal syntax then the variables value is not incremented. Here’s an example of what I found!

The below code shows a very simplified version of the code scenario, bug and all. The bug is on line 17 where at the root node I had left in an increment operator that I had removed from all other assignments to the array within the loop and added to the end. In CF8 this was working fine because level was not being incremented. In CF9 level was being incremented, as is should have been in CF8, and the root node was being added one index past where it should have been at the end of the array. I have tested this with adding both a structure and an array using the literal syntax and in both cases level is not incremented. When assigning a simple value or a variable that references an array or structure level is incremented. Weird!!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Recommended reading

  • Ben Nadel Articles on “obsessively thorough web development” with Coldfusion and jQuery
  • Christian Heimann's blog – Wait till I come!! Articles on web development
  • David Walsh Articles around PHP, CSS, MooTools, jQuery and just about everything else
  • John Resig Javascript programmer and the creator of the jQuery library
  • Mary Lou (Codrops) Stunning designs with lots of cool jQuery effects

Photostream

  • Loading photostream from Flickr...