Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Bug in ArrayIsDefined?

New Here ,
Oct 02, 2008 Oct 02, 2008
Okay, this is either stupidly simple or there is a bug in ArrayIsDefined. If I code the following

<cfset myArray = Arraynew(2)>

<cfset myArray[1][1] = 1>
<cfset myArray[1][2] = 2>

<cfoutput>#ArrayIsDefined(myArray[1], 3)>

The code bombs when run saying that the array only has two elemets. If I put an additional <cfset myArray[1][3] = 3>, then the code returns "YES" . Anybody else seeing this? What stupid thing am I doing wrong?

Thanks
Jim
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008
quote:

Originally posted by: JCox

<cfoutput>#ArrayIsDefined(myArray[1], 3)>

What stupid thing am I doing wrong?


Like missing octothorps?
or not doing it like the manual explains?
or something else?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008
JCox wrote:
> What stupid thing am I doing wrong?
>
> Thanks
> Jim

I will not say stupid, since I have never used this function before and
had to look this up in the documentation. I will even agree that this
not intuitive behavior to me. Finally, this is not even in the
documentation itself, but in the comments of the livedocs version of them.


http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_a-b_12.html
...

halL said on Dec 20, 2007 at 2:10 PM :
...
Also, the ArrayIsDefined function throws an error if you test for an
element beyond the length of the array.
To prevent this error, you can surround the test in a test using the
ArrayLen function.
...

So in summation. ArrayIsDefined() apparently is only used for looking
for empty elements within an existing array. If you are checking if an
array is created or for elements beyond the length of an existing array,
use other functions!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008
> So in summation. ArrayIsDefined() apparently is only used for looking
> for empty elements within an existing array. If you are checking if an
> array is created or for elements beyond the length of an existing array,
> use other functions!

Dear god. You're kidding me? That's a bit crap.

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008
Adam Cameron wrote:
>
> Dear god. You're kidding me? That's a bit crap.
>

Apparently so my dear Adam.

I must admit the description and discussion of this function did not
sell me on its compelling reason to exist. I sure can not imagine any
place in my CF development history where I wished for this functionality.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 02, 2008 Oct 02, 2008
Thanks for the suggestions and info. If you read through the documention and the notes on the live docs, it appears that I'm not the first to notice this. Anyway, I really think the documentation needs to be changed big time. Even knowing what I know, it still sounds like you should be able to test for non-existent array elements in the same way you can use IsDefined for variables.

Jim
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008
> Apparently so my dear Adam.

!!!!

;-)

Well I've raised an issue with the Adobe bods, so possibly it might get
seen to.


> I must admit the description and discussion of this function did not
> sell me on its compelling reason to exist. I sure can not imagine any
> place in my CF development history where I wished for this functionality.

Back in the days of yore I got into some trouble in situations that we had
"sparse" arrays, and it was a right pain in the arse to detect whether a
given element was defined or not. The oft-used try/catch method is dog
slow, and the "use the underlying Java array functions" isn't something I
like to fall back on for something as dumb as this sort of requirement
(dumb because one shouldn't have *had* to fall back on Java for this).

It took them so long to come up with the function under discussion here
that I've long since given up using sparse arrays, so I've never had need
for the function now. That and we're still using CFMX7 for most of the
stuff I'm working on :-(

Anyway. I find if one complains about things, sometimes they get fixed.
So let's see...

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2008 Oct 02, 2008
Adam Cameron wrote:
> Well I've raised an issue with the Adobe bods, so possibly it might get
> seen to.

Cool, It's nice to have friends in important places.

> Back in the days of yore I got into some trouble in situations that we had
> "sparse" arrays, and it was a right pain in the arse to detect whether a
> given element was defined or not.

Ah... I've never made use of 'sparse' arrays and I did not know that
detecting an unused array element was so problematic. Before my CF
development career, my coding experience was much more 2nd and 3rd
generation languages. I don't think anything I used then would even
allow an empty array element. The act of defining an array created a
row of memory boxes, whether you put something in each box or not.

And this is how I still largely look at them. Anytime I can remember
that would have had a situation that might use something like a sparse
array, I would of just made use of structures. The detection of the
existence of a structure key or not is rather trivial.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 10, 2009 Nov 10, 2009

This "bug" is still present in ColdFusion 9 and is truly counter-intuitive for how I thought the function should be used.  I expected it to work properly on indexes greater than the array length.  It's too bad this hasn't been addressed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 10, 2009 Nov 10, 2009
LATEST

Well, the bug tracker is public now, so you can all go and express your distain:

http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=73121

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources