ColdFusion:在CFC中保留变量关键字是否安全? [英] ColdFusion: Is it safe to leave out the variables keyword in a CFC?

查看:46
本文介绍了ColdFusion:在CFC中保留变量关键字是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ColdFusion组件(CFC)中,是否必须对变量范围的变量使用完全限定的名称?

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>

对此吗?

<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>

推荐答案

在创建变量时指定变量"并不重要,因为foo默认情况下将置于变量范围内;但是访问变量很重要.

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.

<cfcomponent>
    <cfset foo = "a private instance variable">

    <cffunction name="doSomething">
        <cfargument name="foo" required="yes"/>
        <cfset var bar = "a function local variable">
        <cfreturn "I have #foo# and #bar#.">
    </cffunction>

    <cffunction name="doAnotherThing">
        <cfargument name="foo" required="yes"/>
        <cfset var bar = "a function local variable">
        <cfreturn "I have #variables.foo# and #bar#.">
    </cffunction>

</cfcomponent>

doSomething("args")返回我有 args 函数局部变量"

doSomething("args") returns "I have args and a function local variable"

doAnotherThing("args")返回我有变量的私有实例函数局部变量."

doAnotherThing("args") returns "I have a private instance of a variable and a function local variable."

这篇关于ColdFusion:在CFC中保留变量关键字是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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