Lucee 5 converts array of structs into struct containing structs

Description

See the gist below. Creating an array that contains structures using bracket notation behaves differently than using array(). The array with bracket notation is converted to a struct and when it is looped through only the key is output. You must loop through it using a collection. This does not occur in lucee 4. Using array() it works in both, but the documentation says to use the bracket notation.

https://trycf.com/gist/e5c344229e5ca4671b7166bff6cdcb3d/lucee5?theme=monokai

Environment

Lucee 4 or 5 on Linux/Amazon/Trycf.com

Activity

Jacob Steelsmith 
16 May 2019 at 15:29

I apologize. I found the issue. It’s with my sloppy code working in Lucee 4. This works using cfloop and array in 4 but not 5:

[ test1 = {foo = ‘bar'}, test2 = {bar = 'foo’} ]

This works in both and is what the documentation says:

[ {foo = ‘bar'}, {bar = 'foo’} ]

Thanks for everyone’s time.

Michael Offner 
16 May 2019 at 07:15

this creates an array with 4 elements in it

[1,2,3,4]

 

this creates an ordered struct with 4 elements

 

[a:1,b:2,c:3,d:4]

 

the first example is what you see in the doc, the second is what you are doing in cftry

 

sitenote: you can always use the attribute index AND item with cfloop.

i don’t see anything wrong atm, please clarify what you think works wrong.

 

Jacob Steelsmith 
16 May 2019 at 06:19

Sorry but the documentation here seems to use the exact same syntax and even recommends it. I'm very tired but am I missing something?

https://docs.lucee.org/reference/functions/array.html

 

Jacob Steelsmith 
16 May 2019 at 06:13

Thank you sir.

Brad Wood 
16 May 2019 at 05:58

The Lucee 4 behavior looks like a bug in the parser as that has never been an acceptable way to declare an array that I know of. The syntax you are using is actually a feature in Lucee 5 that allows you to create ordered struct literals.

The reason the “cfloop array=…” errors is because you haven't created an array, but an ordered struct (as you can see in the dump).

If you test this on Adobe CF 2018, you will see the same behavior there as well.

Closed

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 16 May 2019 at 05:22
Updated 24 May 2019 at 12:42
Resolved 24 May 2019 at 12:42