What's the difference b/t using the variables scope as you mentioned below for my function variables and declaring my variables using var for the query within the function (your excerpt below)? Should I just say:
<!--- local variables for function ---> <cfset var id = 0/> <cfset var name = ""/> <!--- query variable in function ---> <cfset var member = 0/> in my init function rather than: <!--- local variables for function ---> <cfscript> variables.id = id; variables.name = ""; </cfscript> <!--- query variable in function ---> <cfset var member = 0/> ? >> >> >>Frankly, I'd just use the variables scope directly - omit the >>structNew() line above and just do this instead: >> >> variables.id = id; >> variables.name = ""; >> >> >> >> <cfquery name="member" maxrows="1" datasource="mp2"> >> >> >>Be warned that this is not thread safe. All function-local variables - >>including those created by CF tags - should be declared at the top of >>the function using 'var', e.g., >> >> <cfset var member = 0/> >> ... >> <cfquery name="member" ..> Mark Kecko Technology Director MediaPost Communications [EMAIL PROTECTED] 212-204-2002 Sean Corfield wrote: > On 4/13/05, Mark Kecko <[EMAIL PROTECTED]> wrote: > >>In addition to my original post below, I have a question about the >>instance scope. What is it and should I be using it? > > > It's just a programming convention. I actually don't recommend using it. > > >><cfcomponent displayname="Member Qualifiers"> >> <cfproperty name="id" type="numeric" default="0"> >> <cfproperty name="name" type="string"> >> <cfproperty name="email" type="string"> > > > <cfproperty> is pointless unless you're writing a complex web service. > Don't use it, it will only confuse you and anyone else who reads your > code. > > >> <cffunction name="init" access="public" output="false" >>returntype="struct"> >> <cfargument name="aid" type="numeric" default="0"> >> <cfscript> >> instance = structNew(); > > > I think this is bad practice. It's equivalent to: > > variables.instance = structNew(); > > >> instance.id = id; >> instance.name = ""; > > > Frankly, I'd just use the variables scope directly - omit the > structNew() line above and just do this instead: > > variables.id = id; > variables.name = ""; > > >> <cfquery name="member" maxrows="1" datasource="mp2"> > > > Be warned that this is not thread safe. All function-local variables - > including those created by CF tags - should be declared at the top of > the function using 'var', e.g., > > <cfset var member = 0/> > ... > <cfquery name="member" ..> > >> <cfset this.init(arguments.aid)> > > > When you're making calls to methods on the same object, don't use > 'this.', just call the method: > > <cfset init(arguments.aid) /> > >> <cfquery name="member_update" datasource="mp2"> > > > Again, var-declare member_update for safety. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Purchase Flash MX Pro from House of Fusion, a Macromedia Authorized Affiliate and support the CF community. http://www.houseoffusion.com/banners/view.cfm?bannerid=57 Message: http://www.houseoffusion.com/lists.cfm/link=i:12:6732 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/12 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:12 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.12 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
