Generally I think you should avoid any kind of magic that happens like this case, where essentially you require getdetail to be called before getdescription, even though there is nothing that would indicate that that needs to happen to the outside world. This is a gross violation of encapsulation that is likely to get you into trouble.
Something like Aaron suggested would be a better way to achieve the result you seem to want. My only change would be that I would return "" if the description didn't have a length instead of failing to return anything. Although, I wonder if it has the same result. Sam On 10/16/07, Kevin <[EMAIL PROTECTED]> wrote: > > > I have been trying to teach myself cfc's and I am having trouble > understanding this. > > I know you should var scope any variables that are available only to > the instance in a call to a method. > > But should they always be scoped locally? > eg. > > I have a function in a products.cfc > > <cffunction name="getdetail" access="public" returntype="query"> > <cfargument name="item" default="" required="yes" type="numeric" /> > <cfset qry_detail = ""> > <cfquery name="qry_detail" datasource="#variables.datasource#"> > SELECT TITLE, DESCRIPTION FROM mytable WHERE item = <cfqueryparam > cfsqltype="cf_sql_integer" value="#arguments.item#" /> > </cfquery> > </cffunction> > > I have another function in the same cfc that uses the query to get a > field if it has a value. > > <cffunction name="getdescription"> > <cfif len(qry_detail.DESCRIPTION) and qry_detail.DESCRIPTION neq 0> > <cfreturn qry_detail.DESCRIPTION> > </cfif> > </cffunction> > > And i just call it in the .cfm with #products.getdescription()#. > > Now I have been reading that if the var scope is not used on the > query, a race condition can happen. > > But if I use > <cfset var qry_detail = ""> > qry_detail.DESCRIPTION is not available to the getdescription function. > > Can a query used like this cause a race condition? Or should I redo > the functions to contain the query only within var scope the cfc? > > Thanks ahead. > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CFCDev" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfcdev?hl=en -~----------~----~----~----~------~----~------~--~---
