StructKeyExists with NULL values in CFML

Hi there,

Is this a bug?

form.allGood = myJunkScope?.myJunkStruct?.myjunkNestedStruct?.theKeyImAfter;
    writeDump("#structKeyExists(form, "allGood")#");
    // returns FALSE

but if I dump the form - the allGood variable is seen.

form.allGood = myJunkScope?.myJunkStruct?.myjunkNestedStruct?.theKeyImAfter;
    writeDump("#structKeyExists(form, "allGood")#");
    // returns FALSE
    writeDump(var="#form#");
    // allGood key DOES exist in dump of form - with a NULL value.

Shouldn’t the structKeyExists() call return true?

We’re using v5.3.10.120
(yes, we know it’s old!)

structkeyexists returns false for null values

I think this is a bug - at least in the sense that it behaves differently than I think it would be reasonably assumed that it should.

The function asks whether a key exists… not whether or not a key exists AND the value is not null.

I am happy to raise a ticket and also to create a PR for the docs, to note it’s current behaviour when the value is null.

Does anyone have any comments, before I do so?

mate, this is simply how cfml works, do some quick research if you don’t believe me

don’t raise a ticket.

it works differently when full null support is enabled

Hi Zac,

You beat me to it.
I worked out that - if you enable NULL support - then structKeyExists() behave entirely as I would expect.

Would you accept a DOCS PR - for the differentiation of it’s behaviour, depending on the NULL Support setting?

1 Like

absolutely, that would rock!

2 Likes

thanks, i tweaked a bit to refer to CFML rather than Lucee and cross referenced it to the null support docs

and I enabled / updated the isNull() tests

1 Like