Error Building Struct with CreateUUID

This is more for myself than anyone else, but I hit an odd snag in ColdFusion this morning. I got an error when trying to create a new structure member using a CreateUUID() function and ColdFusion's shorthand structure notation. The following code fails:

<cfset CurrentOrder.Cart[CreateUUID()] = {type = "foo"} />

The error I receive is that "Element 435A2A8C-0B35-C81F-4F36BE50E1B8F394 is undefined in a CFML structure referenced as part of an expression." Well duh! I'm trying to create it!

So I changed the code to this, which works perfectly:

<cfset myvar = CreateUUID() />
<cfset CurrentOrder.Cart[myvar] = {type="foo"} />

Does anyone have any idea why using the CreateUUID() function directly in the assignment statement would cause a problem?

7 responses to “Error Building Struct with CreateUUID”

  1. Azadi SaryevAzadi Saryev Says:
    i do not exactly know why, but:
    a) i think it has something to do with the way cf evaluates things with implicit array/structure notation;
    b) it is definitely related to http://www.bennadel.com/index.cfm?dax=blog:1545.view

    Azadi

    Azadi Saryev Says:
    i do not exactly know why, but:<br />a) i think it has something to do with the way cf evaluates things with implicit array/structure notation;<br />b) it is definitely related to <a rel="nofollow" href="http://www.bennadel.com/index.cfm?dax=blog:1545.view">http://www.bennadel.com/index.cfm?dax=blog:1545.view</a><br /><br />Azadi

  2. Bradley MooreBradley Moore Says:
    Best guess, it has something to do with how structs are created using the curly brackets.

    This works:
    <cfset foo[ createUUID() ] = true />

    This also works:
    <cfset foo[ createUUID() ] = {} />

    This fails:
    <cfset foo[ createUUID() ] = { value = true } />
  3. Garrett JohnsonGarrett Johnson Says:
    strange! Must be an odd assignment thing...

    It likes this though...

    <cfset foo = {type = "foo"} />
    <cfset CurrentOrder.Cart[createUUID()] = foo />

    or

    <cfset CurrentOrder.Cart[createUUID()] = {} />

    Garrett Johnson Says:
    strange! Must be an odd assignment thing...<br /><br />It likes this though...<br /><br /><cfset foo = {type = "foo"} /><br /><cfset CurrentOrder.Cart[createUUID()] = foo /><br /><br />or<br /><br /><cfset CurrentOrder.Cart[createUUID()] = {} />

  4. Garrett JohnsonGarrett Johnson Says:
    Appears to be a struct literal problem... not a uuid issue...

    http://www.barneyb.com/barneyblog/2008/07/14/coldfusion-struct-literals-fail-again/
  5. John WhishJohn Whish Says:
    This is a wild stab in the dark, but I wouldv'e thought that it is something to do with the order that ColdFusion evaluates your code. I think that it is probably doing the "currentOrder.Cart" before it generates the CreateUUID() key name.
  6. Daniel ShortDaniel Short Says:
    Yep, I was reading his post yesterday as well. Looks like we're both hitting the same silly issue.
  7. Daniel ShortDaniel Short Says:
    Yep, my experience exactly.

Leave a Reply

Leave this field empty:

Powered by Mango Blog.