I can understand Dave's point about the CFCATCH "scope" because that is a
special variable created by CF -- but, dont' get confused: ALWAYS use a var
statement to create any variable you are going to create local to your
function (same goes inside CFCs and outside CFCs).

The name of a query, the name of a return variable from CFDIRECTORY/CFFILE,
etc. should most certainly  be created with a var statement for all the
usual reasons.   In those cases, the variables you end up creating will
behave the same way as any variable -- unless they are local to the function
they are going to be the equivalent of in the variables scope -- which could
cause name collisions (and, in the case of CFCs, will live for as long as
the CFC instance lives).

As for Jay's issue with CFCATCH, one initial test suggests that CF is
"smart" about the CFCATCH scope:

<cfcomponent>
        <cffunction name="divBy0">
                <cftry>
                        <cfset foo = 9/0>
                        <cfcatch>
                                <cfset nonExistentVariable()>
                                <cfreturn cfcatch>
                        </cfcatch>
                </cftry>
        </cffunction>
        <cffunction name="nonExistentVariable">
                <cftry>
                        <cfset foo = I_DO_NOT_EXIST>
                        <cfcatch>
                                <cfreturn cfcatch>
                        </cfcatch>
                </cftry>
        </cffunction>
</cfcomponent>

If you run the divBy0 method and dump what it returns you get the right
CFCATCH block, even though it was not declared with a var statement.

I can assure you that CFCs are not an after-thought -- they certainly have
their limitations and we've already seen some growing pains, but don't doubt
that they are the single biggest improvement to ColdFusion since the
introduction of Custom Tags.






> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Dave Watts
> Sent: Thursday, November 06, 2003 11:39 AM
> To: '[EMAIL PROTECTED]'
> Subject: RE: [CFCDev] Native CF tags and local scope
>
>
> > I get an ear-full all the time to var scope every variable
> > that is created inside the CFC. Now I hear that's not the case
> > and that CF tags that return structures do not need to be varred.
>
> Well, don't just take what I say at face value anyway - Nathan just said
> they do, and he's a pretty smart guy!
>
> > Please clarify what you mean by they will go out of scope
> > very quickly.
>
> The CFQUERY scope only exists until you run another query, so you already
> have to copy it into another variable if you want to avoid having it
> clobbered by the next query you run. The CFCATCH scope only
> exists within a
> CFCATCH block, and I think it's really unlikely that you'd have
> one CFCATCH
> block clobber another, unless you invoke a component within a
> CFCATCH - and
> even then, I'm not sure it gets clobbered anyway, although presumably it
> would.
>
> However, you probably can't go wrong by following Nathan's advice here,
> since it doesn't hurt anything to create a couple more local variables.
>
> Dave Watts, CTO, Fig Leaf Software
> http://www.figleaf.com/
> voice: (202) 797-5496
> fax: (202) 797-5444
>
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev'
> in the message of the email.
>
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.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 word 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

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

Reply via email to