Confusion over access to dynamic variables in ColdFusion

Below is the code I'm using.

<cfset variables.test1 = 'interface.temp1'> <cfset variables.test2 = 'interface.temp2'> <cfset variables.test3 = 'variables.' & variables.test2> <cfset variables["#variables.test1#"] = 23> <cfset "#variables.test3#" = 50> <cfdump var="#variables#"> <cfdump var="#variables['interface.temp1']#"> 

The attached image describes the output I receive. The first cfdump displays the value of "interface.temp1" as "undefined", and the second cfdump displays the value "23". If you also look at the first cfdump, it displays all the variables in the VARIABLES area, but there is no variable having the value "23", and then in the second cfdump, where does it get the value "23" from?

Please help me find out the reason for this.

+7
coldfusion coldfusion-9
source share
1 answer

I hacked it. I write it completely on my blog: " Odd behavior using structure keys with dots in their names ."

Basically, if you have a substring called interface , which - as stated in @Leigh - is created as follows:

 <cfset "#variables.test3#" = 50> 

Then ColdFusion (and, fwiw, Railo) get confused when trying to resolve structure keys prefixed with interface. : he sees these links as key references in the interface structure, not just the key names.

If you do not have this line of code above, then CF is able to see the exact value with dots.

+2
source share

All Articles