var范围和模块调用在cfc [英] var scoping and module calls in a cfc

查看:120
本文介绍了var范围和模块调用在cfc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在CFC中有一个方法需要通过模块调用调用某些旧代码(执行一些关键功能),我是否有变量出血的风险?例如:

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>

在这个例子中使用caller.qData我污染调用CFC的变量范围,即使我've var scoped 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?

感谢任何洞察。

推荐答案

好吧,显然这不是那么难以测试,因为我是做出来的(感谢大卫Faber的建议)。通过在cfc中转储变量范围,我们可以很容易地看到 cfmodule 调用是否污染了cfc的变量范围。这发生在cfmodule使用自己的 caller 作用域时。

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.

事实证明, var scoping在调用cfmodule之前的方法中的任何有问题的变量。事实上,这可以防止 cfmodule 变量的泄漏。

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.

没有var作用域变量方法,渗出确实发生(如预期的)。这是我的预感,但我想完全确定考虑到的影响。谢谢!

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!

这篇关于var范围和模块调用在cfc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆