Page 1 of 1

Undefined element of (assoc) array shown as 'string'

Posted: 08 Jul 2023 00:37
by PeterH
I'd expect vartype() to show an undefined element of an (associative) array as 'undefined'.
But it's shown as 'string'. To repro (see following script):

- Array $GAf[] is undefined
- Define it by setting one element "c" to 0
- now check any other (non-existing) element by VarType(): it's shown as "string"
- (should be "undefined", I think)

- set a yet undefiined element to 3
- VarType() now shows it correct as "int".

Result: an undefined element can't be recognized!

(Sample script, made from a real world script. There the array is Global - but that makes no difference.)

Code: Select all

//ยง
"Test"
   step;
   $GAf["c"] = 0;                   // define $GAf[] by setting 1 element
   $exist  = VarType($GAf["abc"]);  // is undefined, but shown as "string"
   $exist  = VarType($GAf[11]);     // is undefined, also shown as "string"

   $GAf["abc"] = 3;                 // define it by setting to 3
   $exist  = VarType($GAf["abc"]);  // now correct shown as "int"

Re: Undefined element of (assoc) array shown as 'string'

Posted: 16 Jul 2023 11:24
by admin
Agreed! :tup: Next beta. :cup:

Re: Undefined element of (assoc) array shown as 'string'

Posted: 16 Jul 2023 11:27
by PeterH
:tup:

Re: Undefined element of (assoc) array shown as 'string'

Posted: 18 Jul 2023 23:44
by PeterH
Prev :tup: was for implementing, now a :tup: for testing.

Is it so that I alone found > 80% of bugs with arrays? :whistle:

Re: Undefined element of (assoc) array shown as 'string'

Posted: 18 Jul 2023 23:49
by admin
Looks like it, arrayzor head!

Re: Undefined element of (assoc) array shown as 'string'

Posted: 18 Jul 2023 23:55
by PeterH
:roll: