Why Isn’t There a Local Scope?

I was giving a presentation today on CFC’s, and was explaining the difference between the variables scope, the ‘local’ scope, the this scope, and the arguments scope. It was incredibly hard to explain, mostly because an unscoped variable in a CFC function can refer to either a local, variable-scoped, or arguments-scoped variable.

It made me think, why didn’t they just create another default scope named ‘local’?

However, I realize the ColdFusion development team has some noggin-horsepower, so I’m sure there is a good reason. I just can’t think of it.

3 thoughts on “Why Isn’t There a Local Scope?

  1. It gets a little complicated under the hood as a UDFs ‘local’ scope can be assigned variables in 4 different ways. The first are variables passed into the UDF that also have a CFARGUMENT tag. Variables passed into a UDF without a matching CFARGUMENT tag are NOT automatically part of the local scope. The second are the result of CFARGUMENT tags with default values. The third are CFARGUMENT tags without default values, but this is a special case. CFArgument tags without a default and without a passed value create a ‘space holder’ for a local variable that can be filled within the UDF. The fourth are variables set with a var prefix inside the UDF.

    I cover this in depth in my “From User-Defined Functions to ColdFusion Components” chapter in the latest FAQ-U (small plug). 🙂

    Like

  2. Michael… whilst that’s all very interesing… how does all that make it difficult to give the local scope a NAME?


    Adam

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s