If I am understanding and using this correctly, a variable in a cfc that is declared into the "Variables" scope will be visible to all other methods on the CFC, but not to callers outside of the cfc. A variable in a cfc that is declared into the "This" scope is also visible to all other methods, but also visible and changeable from the calling code. So in the example A (see below) variable "A" will be visible to the caller, but variable "B" will not. So if we were to utilize the following code:
<cfset testObj = createObject("component","test")> <cfinvoke component="#testObj#" method="init"> <!--- this will work ---> <cfoutput>#testObj.A#</cfoutput> <!--- this will throw an error ---> <cfoutput>#testObj.B#</cfoutput> Ok, I believe I have a pretty good handle on all that, but I wanted to explain my current understanding, so that if anybody notices something flawed in my logic, please let me know. Now onto the interesting part I stumbled upon when I was practicing the above. If one adds code such as below, things can get confusing. <cfset testObj.C = "new Value"> <cfoutput>#testObj.C#</cfoutput> This will work, it is in effect adding a new variable to my object. Is this expected and correct behavior? Should any old programmer be able to add new values to any old component object? Would there ever be a good reason to use and/or rely on this behavior? Or is it just a potential gotcha of which to be aware? Doesn't seem to cause a problem, since the new variable is cleanly in the "This" scope of the component, it doesn't seem to clash with similarly named variables in the "Variables" scope. But could it be a problem if one wasn't following the best practice of always scoping one's variables? -------------- Ian Skinner Web Programmer BloodSource Sacramento, CA ***************************** *** simple code example A *** ***************************** <cfcomponent hint="sample a"> <cffunction name="init"> <cfset this.A = "Hello"> <cfset variables.B = "World"> </cffunction> </cfcomponent> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/lists.cfm?link=t:4 Subscription: http://www.houseoffusion.com/lists.cfm?link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Get the mailserver that powers this list at http://www.coolfusion.com