foundeo / cfdocs

Repository for the cfdocs.org site.
https://cfdocs.org/
Other
180 stars 341 forks source link

structKeyExists #1630

Open bagnacauda opened 10 months ago

bagnacauda commented 10 months ago

The description should be updated to reflect the fact that if used on a scope, such as arguments, the function returns false even though the key is present (as seen using writeDump), with value undefined.

Tested on every Adobe ColdFusion version on trycf.com

Short example

<cfscript>
function testFunction(whatever) {
    writeDump(var=arguments, label='arguments');
    if(structKeyExists(arguments, 'whatever')) {
        return 'found';
    } else {
        return 'not found';
    }
}

</cfscript>

<cfoutput>
    #testFunction()#
</cfoutput>
pfreitag commented 10 months ago

I think the issue is more so the fact that if the value is null, then structKeyExists returns false, for example:

<cfscript>
s = {};
s.whatever = javaCast("null", 0);
writeDump(s);
writeOutput( structKeyExists(s, "whatever") );
</cfscript>

In your example you are not passing the whatever argument to the function, so it has a null value as well.

I think it would be worth documenting that when a structure value is null, structKeyExists will return false - anyone else have opinions?