Skip navigation
Currently Being Moderated

CF creating spurious variables

Feb 26, 2011 4:15 AM

G'day

I hope the forums are in a good mood today, and will allow me to paste code in here.  Let's see...

 

Could I ask y'all a favour?  Could you pls run this code on CF9, and let me know the results:

 

 

<cfif structKeyExists(URL, "bung") AND URL.bung>
    <cfset st = {
        foo = "bar"
    }>
<cfelse>
    <cfset st = structNew()>
    <cfset st.foo = "bar">
</cfif>
<cfloop item="sKey" collection="#variables#">
    VARIABLES.<cfoutput>#sKey#</cfoutput> found.  Value:<br />
    <cfdump var="#variables[sKey]#" label="#sKey#">
    <hr />
</cfloop>
<cfdump var="#variables#" label="variables">

 

(contrast the results when passing ?bung=true and ?bung=false on the URL.

 

We are seeing CF creating a spurious variable "___IMPLICITARRYSTRUCTVAR0" being created in the variables scope, when using {} notation for creating structs.

 

This does not happen on CF8, but does happen on CF9 (9.0, 9.0.1, 9.0.1+CHF).

 

It only happens when the code is in a CFM file; not a CFC file.

 

It's "interesting" that Adobe are suppressing the output of this variable in CFDUMP.

 

--

Adam

 
Replies
  • Currently Being Moderated
    Feb 26, 2011 4:42 AM   in reply to Adam Cameron.

    forum_test.jpg

    This is the result without query-string or when the query-string is ?bung=false.

    My ColdFusion build: 9.0.1.274733.

     

    Message was edited by: BKBK

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2011 4:39 AM   in reply to Adam Cameron.

    Now with query-string ?bung=true

     

    forum_test.jpg

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2011 4:58 AM   in reply to Adam Cameron.

    Peculair find, indeed. A Google search revealed just one instance of the term IMPLICITARRYSTRUCTVAR0 on the web.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2011 7:02 AM   in reply to Adam Cameron.

    Clearly a bug. I have been able to reproduce it -- always! (Note, however, my CF version above.)

     

    I have learned something new from this exercise. I never realized until now that <cfloop item="myKey" collection="#myCollection#"> adds myKey to the variables scope!

     

    The IMPLICITARRYSTRUCTVAR0 never occurs when you use this code:

     

    <cfset st.foo1 = "foo1">
    <cfset st.foo2 = "foo2">
    <cfloop item="sKey" collection="#variables#">
        Key:<cfoutput>#sKey#</cfoutput><br>
      <cfdump var="#variables#">
    <hr />
    </cfloop>

     

     

    The IMPLICITARRYSTRUCTVAR0 never occurs when you use this code:

     

    <cfset st = {foo1 = "foo1", foo2 = "foo2"}> 
    <cfloop item="sKey" collection="#st#">
      <cfdump var="#variables#">
    <hr />
    </cfloop>

     

    However, the IMPLICITARRYSTRUCTVAR0 always occurs when you use this code:

     

    <cfset st = {foo1 = "foo1", foo2 = "foo2"}> 
    <cfloop item="sKey" collection="#variables#">
      <cfdump var="#variables#">
    <hr />
    </cfloop>

     

    Apparently, when you use the new curly-bracket notation for structs and you loop through the variables structure, ColdFusion adds the extra key IMPLICITARRYSTRUCTVAR0 to the variables structure.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 26, 2011 9:45 AM   in reply to Adam Cameron.

    Adam Cameron. wrote:

     

    Oh yeah, forgot to say. I don't think it's anything to do with the loop, per se.  I'm on a train to the pub to watch England v France (Six Nations), so cannae check, but you should just be able to do this:

     

    st = {};

    writeOutput(structKeyExists(variables, "___IMPLICITARRYSTRUCTVAR0");

     

    Say what? Computer says yes! Nice counterexample!

     

    Gets me thinking perhaps Javaman forgot to take out the placeholder for index 0 after the design phase. The code

     

    <cfset st = {}>
    <cfoutput>
    structKeyList(variables): #structKeyList(variables)#<br>
    isDefined("variables.___IMPLICITARRYSTRUCTVAR0"): #isDefined("variables.___IMPLICITARRYSTRUCTVAR0")#
    </cfoutput>

     

    gives the result


    structKeyList(variables):  ___IMPLICITARRYSTRUCTVAR0,ST
    isDefined("variables.___IMPLICITARRYSTRUCTVAR0"):  YES

     

    But then again, the variable ___IMPLICITARRYSTRUCTVAR0 is nowhere to be found in <cfdump var="#variables#">

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points