I like that, but mainly because we are not given a "local" scope to use within the functions.  Personally I wish the language would have something like local as a built in scope for local sets in a function.  Kind of like on a CFM page if you leave off a scope in your set it goes into the "Variables"  This is something that put me off when first going to CFCs because on a typical CFM page if I do <cfset blah = "" /> then I refer to it as Variables.blah but that right there had to change when writing CFCs for obvious reasons.  I'd be happy if I could do <cfset var blah = "" /> then refer to it as local.blah  but that is just because I have that habbit ingrained in me from so many years.

On 6/28/06, Cody Caughlan <[EMAIL PROTECTED]> wrote:
I like declaring one struct as local, e.g.

<cfset var local = StructNew()>

And then *all* my variables in a function get put into this struct, e.g. all loop counters, query
names, etc. *everything*.

This is great because once you start doing this and then later you look at code and you see a
variable that is all on its own, then you *KNOW* you have a possible problem with your method being
not thread-safe.

/Cody

Aaron Roberson wrote:
> Thanks guys, for some reason I missed that little detail. I spent at
> least an half hour trying to debug this error, that's the sad part.
>
> -Aaron
>
> On 6/28/06, Roland Collins <[EMAIL PROTECTED]> wrote:
>> You should also var your queryparam argument and scope all of the
>> arguments
>> in the body of the function.  Like so:
>>
>>
>> <cffunction name="getArticles" access="public" returntype="query">
>>
>>                 <cfargument name="artID" required="no" type="numeric"
>> default=0>
>>                 <cfargument name="authID" required="no" type="numeric"
>> default=0>
>>                 <cfargument name="catID" required="no" type="numeric"
>> default=0>
>>
>>                 <cfset var queryparam = "">
>>                 <cfset var rsArticles = "">
>>
>>                 <cfif arguments.artID NEQ 0>
>>                         <cfset queryparam = " AND articles.artID =
>> #arguments.artID#">
>>                 </cfif>
>>                 <cfif arguments.authID NEQ 0>
>>                         <cfset queryparam = queryparam & " AND
>> articles.artauthor_ID =
>> #arguments.authID#">
>>                 </cfif>
>>                 <cfif arguments.catID NEQ 0>
>>                         <cfset queryparam = queryparam & " AND
>> articles.artcat_ID =
>> #arguments.catID#">
>>                 </cfif>
>>
>>         <cfquery name="rsArticles" datasource="#variables.dsn#">
>>                         SELECT artID, artcat_ID, artauthor_ID, artTitle,
>> artDesc, artContent
>>                         FROM articles
>>                         WHERE articles.artActive = 1
>>                         #preservesinglequotes(queryparam)#
>>                         ORDER BY artID DESC
>>                 </cfquery>
>>
>>                 <cfreturn rsArticles>
>>         </cffunction>
>>
>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On
>> Behalf
>> Of Aaron Roberson
>> Sent: Wednesday, June 28, 2006 6:32 PM
>> To: [email protected]
>> Subject: [CFCDev] Problem with local var in CFC methods
>>
>> I keep getting this error when I invoke my cfcs:
>>
>> "Local variable rsArticles on line 34 must be grouped at the top of
>> the function body"
>>
>> Here is what my method looks like:
>>
>>         <cffunction name="getArticles" access="public"
>> returntype="query">
>>
>>                 <cfargument name="artID" required="no" type="numeric"
>> default=0>
>>                 <cfargument name="authID" required="no" type="numeric"
>> default=0>
>>                 <cfargument name="catID" required="no" type="numeric"
>> default=0>
>>
>>                 <cfparam name="queryparam" default="">
>>
>>                 <cfif artID NEQ 0>
>>                         <cfset queryparam = " AND articles.artID =
>> #arguments.artID#">
>>                 </cfif>
>>                 <cfif authID NEQ 0>
>>                         <cfset queryparam = queryparam & " AND
>> articles.artauthor_ID =
>> #arguments.authID#">
>>                 </cfif>
>>                 <cfif catID NEQ 0>
>>                         <cfset queryparam = queryparam & " AND
>> articles.artcat_ID =
>> #arguments.catID#">
>>                 </cfif>
>>
>>                 <cfset var rsArticles = 0>
>>                 <cfquery name="rsArticles" datasource="#variables.dsn#">
>>                         SELECT artID, artcat_ID, artauthor_ID, artTitle,
>> artDesc, artContent
>>                         FROM articles
>>                         WHERE articles.artActive = 1
>>                         #preservesinglequotes(queryparam)#
>>                         ORDER BY artID DESC
>>                 </cfquery>
>>
>>                 <cfreturn rsArticles>
>>         </cffunction>
>>
>>
>> ----------------------------------------------------------
>> You are subscribed to cfcdev. To unsubscribe, send an email to
>> [email protected] with the words 'unsubscribe cfcdev' as the subject
>> of the
>> email.
>>
>> CFCDev is run by CFCZone ( www.cfczone.org) and supported by CFXHosting
>> (www.cfxhosting.com).
>>
>> An archive of the CFCDev list is available at
>> www.mail-archive.com/[email protected]
>>
>>
>>
>>
>>
>> ----------------------------------------------------------
>> You are subscribed to cfcdev. To unsubscribe, send an email to
>> [email protected] with the words 'unsubscribe cfcdev' as the subject
>> of the email.
>>
>> CFCDev is run by CFCZone ( www.cfczone.org) and supported by CFXHosting
>> (www.cfxhosting.com).
>>
>> An archive of the CFCDev list is available at
>> www.mail-archive.com/[email protected]
>>
>>
>>
>
>
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email to
> [email protected] with the words 'unsubscribe cfcdev' as the subject of
> the email.
>
> CFCDev is run by CFCZone (www.cfczone.org ) and supported by CFXHosting
> (www.cfxhosting.com).
>
> An archive of the CFCDev list is available at
> www.mail-archive.com/[email protected]
>
>
>
>



----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting ( www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]





--
Aaron Rouse
http://www.happyhacker.com/ ----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]

Reply via email to