ColdFusion Var Bug
Aug 17
Now we all know why we should var our variables in CFC methods. If you don't, the variables you create will bleed into other functions, and can wreak havoc on your application, especially if you cache your CFCs.
Suppose you have a component called MyComponent.cfc.
1<component name="MyComponent">
2 <cffunction name="method1">
3 <cfset var myQry="">
4 <cfquery name="myQry" datasource="myDSN">
5 insert into table (somefield) values (1)
6 </cfquery>
7 <cfquery name="myQry" datasource="myDSN">
8 select * from table where somefield=1
9 </cfquery>
10 </cffunction>
11 <cffunction name="method2">
12 <cfdump var="#myQry#">
13 </cffunction>
14</component>
Now lets say you have a test file that looks something like this:
2<cfinvoke component="#application.myComponent#" method="method1">
3<cfinvoke component="#application myComponent#" method="method2">
What do you expect the output to be? It should just throw an error when you call method2, saying that myQry is not defined. What will happen is you will see the dump of myQry, which has bled out from the other method.
Apparently, what happens is when the first query runs, it doesn't return anything, and the myQry variable gets erased. (If you try dumping it right afterwards, you will see that it's not defined).
When the second query runs, it will create the myQry variable in the standard scope, which is local to the CFC. There are workarounds, but hopefully Adobe will fix it in their next updater.
One such workaround is to use a struct for the local variables, like this:
1<component name="MyComponent">
2 <cffunction name="method1">
3 <cfset var local=StructNew()>
4 <cfquery name="local.myQry" datasource="myDSN">
5 insert into table (somefield) values (1)
6 </cfquery>
7 <cfquery name="local.myQry" datasource="myDSN">
8 select * from table where somefield=1
9 </cfquery>
10 </cffunction>
11 <cffunction name="method2">
12 <cfdump var="#local.myQry#">
13 </cffunction>
14</component>
Now if you try running the same code, you will get an error saying that "local.myQry" is not defined.
#1 by christian louboutin on 6/3/10 - 7:14 AM
However, attitudes have changed, consumers are more educated and if they are prepared to pay a few thousand euros for a bespoke suit with hand-stitched buttonholes and a canvas interlining and purchase a crocodile <a href="http://www.echristianlouboutincom.com/christian-lo... Louboutin Pumps</b></a>, then they are not going to be satisfied with a cynical piece of battery-powered brand extension.
Gildo Zegna of the eponymous men's apparel brand, explains what prompted him to work on a watch with Gino Macaluso, proprietor of Girard <a href="http://www.echristianlouboutincom.com/christian-lo... Louboutin Sandals</b></a>.
#2 by hollister clothing on 7/19/10 - 2:24 PM
#3 by Abercrombie & fitch uk on 7/23/10 - 12:00 PM
I second albertacowpoke's question...
I hate guns If no guns of everyone,the world maybe well.
Think they would read the BILL if they had to live by it?
#4 by r4cardsohot on 7/26/10 - 4:37 PM
#5 by tiffany outlet on 8/3/10 - 9:45 AM
The article is very professionally written. I enjoy reading every day
good url!
good web!
good website!
#6 by tiffany outlet on 8/3/10 - 9:46 AM
The article is very professionally written. I enjoy reading every day
good url!
good web!
good website!
#7 by hollister clothing on 9/10/10 - 2:28 AM
#8 by hollister clothing on 9/10/10 - 2:28 AM
#9 by buy-cheapjerseys on 6/10/11 - 11:49 AM
#10 by buy-cheapjerseys on 6/10/11 - 11:49 AM
#11 by baby198901 on 6/27/11 - 4:23 AM
#12 by nfljerseys88 on 7/24/11 - 11:08 PM
#13 by july on 7/29/11 - 7:58 AM
Thanks for sharing such a nice post. http://www.miningmachine.org
Yifan Mcahinery----Quarry Equipment http://quarry-equipment.com
#14 by Jerseys on 10/15/11 - 1:01 AM