ArrayIsDefined throws CF error
Posted At : February 20, 2008 11:02 AM
| Posted By : Dave
Related Categories:
ColdFusion 8
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:
<CFSET testArray[i] = i>
</CFLOOP>
<CFOUTPUT>
#arrayLen(testArray)#<BR>
#ArrayIsDefined(testArray, 6)#
</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

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