On Apr 4, 2005 11:15 PM, Dave Merrill <[EMAIL PROTECTED]> wrote:
> >
> > <cffunction name="bar">
> > <cfset foo = 42>
> > </cffunction>
>
> Understood, but what's odd is that vars declared inside a function escape to
> the outside at all...
The variable isn't actually "declared" unless you use the var keyword.
Look at the same function in Java.
void bar () {
foo = 42;
}
The variable foo is not local to bar() because it wasn't declared
inside bar(), like so:
void bar () {
int foo = 42;
}
However, if foo wasn't declared within bar() it must have been
declared somewhere else (in the body of the class).
That's the difference between Java and ColdFusion. Pre-CF5, ColdFusion
didn't have any concept of declaring variables, and still doesn't for
the most part. When functions were introduced, Allaire needed a way to
make variables local to a function, so they introduced the var keyword
for that specific purpose.
Personally, I think adding another scope (local.foo or function.foo)
would have been more consistent.
Patrick
--
Patrick McElhaney
704.560.9117
http://pmcelhaney.weblogs.us
----------------------------------------------------------
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]