structKeyExists and null

68 views
Skip to first unread message

Richard Meredith-Hardy

unread,
Oct 19, 2015, 4:43:21 AM10/19/15
to Lucee
can someone tell me what is going on here?

<cfset struct = {"itm1":"sausages","itm2":nullvalue()}>
<cfdump var="#struct#" label="struct">
<cfdump var="#structkeyArray(struct)#" label="struct key array">
<cfdump var="#structkeyList(struct)#" label="struct key list">
<cfdump var="#structkeyExists(struct,'itm1')#" label="itm1 exists - should be true">
<cfdump var="#structkeyExists(struct,'itm2')#" label="itm2 exists - should be true... but this reports false">
<cfdump var="#structkeyExists(struct,'itm3')#" label="itm3 exists - should be false">

This is Lucee 4.5.1.023 with null settings in admin unchanged from default.

I would have thought structkeyexists() should never be influenced by a key's value, whatever the value or whatever the null handling settings....

Regards

Richard


Jon Clausen

unread,
Oct 19, 2015, 6:56:05 AM10/19/15
to lu...@googlegroups.com
That's incorrect. With ACF defaults for null handling, a struct key is considered not to exist if it's a null value.  If you need it to exist, turn on full null support.

On Oct 19, 2015, at 4:43 AM, Richard Meredith-Hardy <r....@flymicro.com>

I would have thought structkeyexists() should never be influenced by a key's value, whatever the value or whatever the null handling settings....

Regards

Richard


--
See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your ticket NOW - http://www.cfcamp.org/
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/2429b8c6-b9f1-4a07-935c-000fedbd1024%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Richard Meredith-Hardy

unread,
Oct 19, 2015, 2:35:34 PM10/19/15
to Lucee
ok, thanks. 

Having had to move stuff between ACF and another [better one] more than once, I like to keep settings 'stock'.  In this case it's easy to check a key in a struct exists even if it has a null value with something like
 listfind(structkeylist(my_struct),my_key)

but it nevertheless seems a bit illogical that structkeyExists() doesn't do it for you ....

Richard

Jon Clausen

unread,
Oct 19, 2015, 2:41:45 PM10/19/15
to lu...@googlegroups.com
You’d have to go back to the Macromedia days of CF server (maybe Allaire) to figure out why that is.  The behavior has been that way for many, many years.  Another reason to develop new apps on Lucee with full null support turned on. :)

BTW, if you have a null value in a struct where you know the key exists in some form, you can always test it with isNull(struct[key]) and get a predictable result.  I always use that when testing function arguments as it’s predictable with either null support on/off.
Reply all
Reply to author
Forward
0 new messages