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:
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
#1 by Adrian J. Moreno on 2/20/08 - 1:42 PM
http://livedocs.adobe.com/coldfusion/8/htmldocs/he...
It's like this is what's happening:
cfset foo = arrayNew(1);
cfset foo[1] = "a";
cfset foo[3] = "c";
arrayIsDefined(foo, 2) ~ Oh, you seem to have missed defining array element 2, FALSE
arrayIsDefined(foo, 4) ~ I don't seem to understand what you're asking here. You stopped at element 3, can't you see that? I mean, element 4? What's element 4? I just don't get it. You're speaking gibberish man. I really don't see ACK! *stroke* CFERROR
#2 by chief on 3/18/08 - 6:15 AM