问题
If I have a method in a CFC which needs to call in some legacy code via a module call (to perform some critical functionality) am I at risk for variable "bleeding"? For example:
<!--- in my cfc --->
<cffunction name="myFunc">
<cfset var qData = "">
<cfmodule template="some_legacy_code.cfm" attr1="hi" attr2="hello">
<cfreturn qData>
</cffunction>
<!--- in some_legacy_code.cfm --->
<cfquery name="qData">
select * from x
</cfquery>
<cfset caller.qData = qData>
By using caller.qData in this example am I polluting the variables scope of the calling CFC even though I've var scoped qData?
What is the best way for me to test this bleed over so I can "see it for myself" considering I can't easily readily replicate multiple simultaneous calls from different requests as a real application might encounter?
Thanks for any insight.
回答1:
Ok, apparently this wasn't as hard to test as I was making it out to be (thanks David Faber for the suggestion). By dumping out the variables scope in the cfc, we can easily see if the cfmodule
call is "polluting" the cfc's variables scope. This occurs when the cfmodule uses its own caller
scope.
As it turns out, this is easily remedied by "var scoping" any problematic variables in the method before making the cfmodule call. Indeed, this does the trick of preventing the cfmodule
variables from bleeding through.
Without the var scoped variables in the method, the bleed over does indeed occur (as expected). This was my hunch, but I wanted to be totally sure considering the implications. Thanks!
来源:https://stackoverflow.com/questions/28631755/var-scoping-and-module-calls-in-a-cfc