Another in the long list of new things in ColdFusion 8 is a new function called ArrayIsDefined. This will allow you to check to see if an array element is defined.

However, I ran into an issue with it that seems kind of odd. If your array has 5 elements and you try to see if array element 6 is defined ColdFusion will throw an error.

Example:

view plain print about
1<CFLOOP INDEX="i" FROM="1" TO="5">
2    <CFSET testArray[i] = i>
3</CFLOOP>
4
5
6<CFOUTPUT>
7    #arrayLen(testArray)#<BR>
8    #ArrayIsDefined(testArray, 6)#
9</CFOUTPUT>

Error: Cannot access array element at position 6. The array has 5 indexes. Valid positions are from 1 to 5.

The error states that the array has a length of 5 and it can't access element 6. Seems a little strange that the CF error tells me what the function should have.

The only work around is to check the length of the array before you check to see if the element exists. Hopefully this will be fixed in a future release.

Till next time...

--Dave