Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


CF creating spurious variables

LEGEND ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

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

Views

2.2K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Feb 26, 2011 Feb 26, 2011
Now with query-string ?bung=true

Likes

Translate

Translate
Adobe Community Professional ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

Now with query-string ?bung=true

forum_test.jpg

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

Thanks.  That's what we're seeing too.  I know of one person who is not seeing this though.  Weird.

--

Adam

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

I've created a bug report:

http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=86496

--

Adam

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

What's even more interesting is that when I googled "___IMPLICITARRYSTRUCTVAR0" the other day... nothing came back.  Now Ben's article; and... very quick of google indeed: this thread; a mirror of this thread; and another coupla mentions of it too.

--

Adam

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

Yeah - re the cfloop/item thing - it's not some sneaky iterator or anything: it's literally just a string holding the key name for each key in turn. It's like doing a list-loop over a structKeyList().

--

Adam

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

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");

--

Adam

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 26, 2011 Feb 26, 2011

Copy link to clipboard

Copied

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#">

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2011 Mar 02, 2011

Copy link to clipboard

Copied

LATEST

Yeah. Sadly I think they have put specific code into dump.cfm to suppress output of that variable.

One would think that of they were going to those lengths, their time might be better spent simply fixing the issue instead.

Oh well: the bug is logged. Very little of our code needs refactoring to avoid this, so I'm not that fussed.

--

Adam

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines