Undefined element of (assoc) array shown as 'string'
Posted: 08 Jul 2023 00:37
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.)
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"