Personally I would have much seen this be addressed in a more "ColdFusion"
way via scoping.  I would have rather seen a "local" scope for functions
just as there is a "variables" scope for the page.

In this case if you set <cfset foo = ""> in the body of the page then it
would assign the variable to the variables scope, in a function body it
would assign it to the local scope.

In other words instead of an "unnamed" function local scope you would have a
named function local scope.

To access the variables scope in a function body you would have to prefix
the variable.  Something like this could have worked:

<cfset foo = 1 />     <-- page variables scope
<cfset variables.foo = 2 />     <-- page variables scope
<cfset local.foo = 1 />     <-- error (unavailable scope)

<cffunction >


        <cfset local.foo = 1 />    <-- function local scope
        <cfset foo = 3 />     <-- function local scope
        <cfset variables.foo = 2 />     <-- page variables scope

</cffunction>


Instead we follow the JavaScript scoping model for declaration.  It's not a
bad model at all, but it's used only here where scoping is used throughout
the rest of CFML for the same purpose.

Either model works just fine, but the name-scope model is more "cf-like" to
me (and, potentially, would have cut down on a lot of the thread-safety
issues).

Jim Davis

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
> Of Barney Boisvert
> Sent: Friday, September 03, 2004 7:25 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [CFCDev] CFC var question
> 
> > But compiler should knows that the variable declarations (with cfset)
> > within a cffunction are local no?
> 
> How, unless you've told it that the variable you're setting is local
> to the function?  Once you tell it "this variable is local", then
> it'll remember, but you have to tell it that at some point.
> 
> <cfset var myVar = 3 />
> <cfset myVar = 4 />
> <cfset myOtherVar = 4 />
> 
> Obviously the first two lines set a local function variable.  THe
> first one does double duty in that it also tells CF that 'myVar' is
> local to the function.  The third line, however, is unclear.  We
> haven't told CF that "myOtherVar" is local to the function, nor have
> we told it that it's local to the CFC instance.  Which one is it?
> 
> That's why we need the 'var' keyword.
> 
> cheers,
> barneyb




----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words '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