REALLY? Oh boy, I have some code to fix. :)
Glad I just started using CFCs... not much code to fix. -----Original Message----- From: Brad Wood [mailto:[EMAIL PROTECTED] Sent: Monday, July 30, 2007 11:00 AM To: CF-Talk Subject: RE: CFC defining vars That makes the variable exist only for the duration of that method call. For instance, you have a CFC which is persisted in the application scope. <cfset application.my_cfc = CreateObject('component','CFC.foo')> It has a method called helloWorld() which queries their name out of the database a returns it. <cfquery name="qry_your_name"> Select etc. </cfquery> <cfreturn qry_your_name.full_name> Now, let's say two different people in the same app call that method at the same time. Right now, qry_your_name will exist in variables, which is global to the entire CFC. Here we just created a race condition. User one's query runs, and then user two's query overwrites. Then the cfreturn hands back the same data to both users. The solution: <cfset var qry_your_name = ""> <cfquery name="qry_your_name"> Select etc. </cfquery> <cfreturn qry_your_name.full_name> Now EACH call to that method has its own qry_your_name variable which can not be overwritten by concurrent usage of the CFC Print this out and place it on your cube wall. I did. :) http://www.coldfusionjedi.com/downloads/cfcscopes.pdf ~Brad -----Original Message----- From: Chad Gray [mailto:[EMAIL PROTECTED] Sent: Monday, July 30, 2007 8:46 AM To: CF-Talk Subject: CFC defining vars I have noticed in a lot of people's code for CFCs they set all of the variables being used in the CFC like this: <cfset var foo = ""> Why? Is this just good programming practice? Also what scope are these variables in? variables.foo? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| ColdFusion 8 - Build next generation apps today, with easy PDF and Ajax features - download now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:284833 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4