Viewing Individual Entry / Main
  ::   August 5, 2003

CFCs: Variables/Unnamed Scope Issue Fixed in MX 6.1
For those of you working with CFCs in ColdFusion MX 6.0, you'll be happy to know that the bug affecting variables scope has been fixed in MX 6.1. Now, both the variables scope, and the unnamed scope (unscoped variables) behave the same way. Here's a breakdown of how the variables/unnamed scope, the local scope (var keyword) and the this scope differ:

Variables/Unnamed Scope
Variables in the variables scope are available only within the CFC. They are available to the constructor code, and to all component methods and any pages they include. They may be prefixed with the variables prefix or left unscoped (often called the unnamed scope). Variables in the variables scope that are set within the calling page are not automatically available within the component’s variables scope. Additionally, variables in the variables scope exist as long as the component object exists. This allows them to persist between method calls.

Local Scope
This differs from variables you set in the "local" scope of a method by using the var keyword. These variables are available only to the method in which they are defined and any pages included by that method. Additionally, local variables do not last beyond the life of the method call. The local variable scope differs from other variable scopes in that there is no scope prefix used for the variable. Note that if you do not define the variable with the var keyword, the variable exists in the variables scope, not the local scope.

This Scope
The this scope is functionally equivalent to the this scope in JavaScript and ActionScript. Variables in the this scope are available to all methods within a CFC, any pages they include, and the page that calls the CFC. Within a CFC you refer to variables in the this scope using the this prefix: this.varName. Outside the CFC, you use the component name to reference variables in the this scope: myComponent.varName. Note that this applies only when the CFC is instantiated as an object via the cfobject tag or createObject( ) function, not when a component method is invoked using the cfinvoke tag, without the CFC being instantiated separately.

I hope this helps put things in perspective!



Calendar
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

Recommended Reading
Imagining Argentina

Archives by Subject
Announcements (28)
ColdFusion (61)
Database (12)
Dreamweaver (1)
Flash (2)
Flash Remoting (2)
Flex (3)
General Development (2)
Homesite + (1)
Mach-II (3)
MAX (9)
Mozilla (2)
Music (1)
Politics (1)
Portals (2)
Travel (2)

Search

Links
CFLib.org
Raymond Camden's Blog
Christian Cantrell's Blog
Sean Corfield's Blog
Nathan Dintenfass' Blog
Todd Rafferty's Blog
Steve Rittler's Blog
Cameron Childress's Blog

Credits
Based on blog.cfc by Raymond Camden

XML Feed