Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

structKeyExists #1630

Open
bagnacauda opened this issue Sep 29, 2023 · 1 comment
Open

structKeyExists #1630

bagnacauda opened this issue Sep 29, 2023 · 1 comment

Comments

@bagnacauda
Copy link

bagnacauda commented Sep 29, 2023

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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants