Skip to main content
Inspiring
February 23, 2012
Answered

Using a reserved name in a structure.

  • February 23, 2012
  • 1 reply
  • 1586 views

I am using CF9's fast way to create a structure, ie:

<cfset myStruct = {

keyName = {

    innerKey1 = "value",

     innerKey2 = "anotherValue"

}

}>

One of the keys I want to make is called "mod", however that is a reserved function (Modulus).  Is there a way I can still use this?

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    When I use the key name of "mod" (with quotes), then when I dump the THIS.CONFIGDATA structure, it shows the parent PATH key, and in it, just the APP and FW keys (along with their inside content).  The mod key does not show up at all.


    Use this code (saved in testFile.cfm):

    <!--- testFile.cfm--->

    <cfset configData = {

    path = {

    app = {

                                  absDataURL = "/acp/app/data/",

                                  absLogicURL = "/acp/app/logic/",

                                  absLogicFQDN = "/acp.app.logic.",

                                  absPresentationURL = "/acp/app/presentation/",

                                  absURL = "/acp/app/",

                                  rootURL = "/acp/"

                        },

      fw = {

                                  absDataURL = "/framework/fw/data/",

                                  absLogicURL = "/framework/fw/logic/",

                                  absLogicFQDN = "/framework.fw.logic.",

                                  absPresentationURL = "/framework/fw/presentation/",

                                  absURL = "/framework/fw/",

                                  rootURL = "/framework/"

                        },

      "mod"= {

                                  absURL = "/acp/mods/",

                                  relDataURL = "/data/",

                                  relLogicURL = "/logic/",

                                  relLogicFQDN = ".logic.",

                                  relPresentationURL = "/presentation/",

                                  rootURL = "/acp/"

                        }

    }

    }>

    <cfdump var="#configData#">

    And post a screen cap of the results.

    --

    Adam

    1 reply

    Inspiring
    February 24, 2012

    So far, the only solution I've been able to find is:

    <cfset myStruct = {

    path = {

    app = { this="that", that="this" },

    mod = { this="that", that="this" }

    }

    }>

    The above will fail because 'mod' is a function.  But I found I could do this (as long as the erroring key has a parent)

    <cfset myStruct = {

    path.app = { this="that", 'that="this" },

    path.mod = { this="that", that="this" }

    }>

    This actually makes a structure that has a parent "path" key and then 2 child keys "app" and "mod" under it, each with 2 key/value pairs.

    I'd rather use the former syntax, but I'm currently using the latter, since CF doesn't see "path.mod" as a built-in function.

    BKBK
    Community Expert
    Community Expert
    February 24, 2012

    What about this?

    <cfset myStruct = {

    path = {

    app = { this="that", that="this" },

    "mod" = { this="that", that="this" }

    }

    }>

    Inspiring
    February 24, 2012

    I tried that and in doing so the actual "mod" key and all it's values inside it don't show up in the final structure at all.