Copy link to clipboard
Copied
This question was posted in response to the following article: http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7ed3.html
Copy link to clipboard
Copied
Since the index value of an element must be less than the length of the array this function ist worth nothing!
Copy link to clipboard
Copied
I disagree. It can be that:
1) You are in a position in the code where you don't know the length of the array;
2) You know the array's length is 3, for example, and you know the values of arr[1] and arr[3]. It is still possible that arr[2] doesn't exist.
Copy link to clipboard
Copied
Sure, in this specific way it would work.
Well, the description says "True, if the array element is defined (exists)". So in my opinion it has to determine, if an index exists, no matter if the index is bigger than the length of the array. The isDefined function does the same. It checks the existance of an variable.
Let's say you loop through an array of users and several users are redundant. Now you would like to determine, if the next user is unequal to the current user. At the last index this funktion would through an error, which is pretty uncomfortable.
The only way to make this function work without errors, would be to check first the current index with the length of an array and after that to use the ArrayIsDefined Function.
Copy link to clipboard
Copied
The usage guidance is wrong: one can test beyond the length of the array, and has been able to do so since CF9.
http://adamcameroncoldfusion.blogspot.co.uk/2012/08/arrays-in-coldfusion-part-2.html#arrayIsDefined
--
Adam
Copy link to clipboard
Copied
We are still using CF8, so I checked the behaviour in later versions and the description mentions the same. One more reason for us to upgrade.
Thanks for the information!