In a ColdFusion Component (CFC), is it necessary to use fully qualified names for variables-scoped variables?
Am I going to get myself into trouble if I change this:
<cfcomponent> <cfset variables.foo = 'a private instance variable'> <cffunction name = 'doSomething'> <cfset var bar = 'a function local variable'> <cfreturn 'I have #variables.foo# and #bar#.'> </cffunction> </cfcomponent>
to this?
<cfcomponent> <cfset foo = 'a private instance variable'> <cffunction name = 'doSomething'> <cfset var bar = 'a function local variable'> <cfreturn 'I have #foo# and #bar#.'> </cffunction> </cfcomponent>
It won’t matter to specify ‘variables’ when you create the variable, because foo will be placed in the variables scope by default; but it will matter when you access the variable.
doSomething(‘args’) returns ‘I have args and a function local variable‘
doAnotherThing(‘args’) returns ‘I have a private instance of a variable and a function local variable.’