StructEach is not accessing key-value accurately for arguments

#1

I created bug in JIRA. This is related to behavior of StructEach function.

When I use StructEach for arguments struct.
Its not accessing correct key and value.

callMe(12345,"test");
function callMe(number,text){
    writedump(arguments);
    
    StructEach(arguments,function(key, value) {
        writeoutput("key: " & key & " value: " & value & ";");
    });
}

This code works in ACF.

To solve the issue, I have to serialize and deserialize the arguments struct.

deserializeJson(serializeJson(arguments)

0 Likes

#2

What is the expected result? https://trycf.com/gist/5570b33b38c418fb5e94864bfe644e57/lucee5?theme=monokai

0 Likes

#3

I think that the arguments scope is different because it can be used as both an array and a struct (i.e. positional vs. key/value args).

0 Likes

#4

Yeah, the ACF behavior makes more sense.

We need to update the docs to explicitly note the closure arguments too.

https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-s/structeach.html
vs

0 Likes

#5

Yes, arguments scope is different, but still it is struct and ACF is giving accurate result. Arguments scope in ACF is positional too.
Lucee needs to fix. Both key and value are inaccurate in the StructEach iteration.

0 Likes