开发者

How to get rid of Evaluate() without local scope (pre-CF9)?

开发者 https://www.devze.com 2023-03-23 05:11 出处:网络
Ok, this func doesn\'t make sense, but I\'m just using it as an example: <cffunction name=\"blah\">

Ok, this func doesn't make sense, but I'm just using it as an example:

<cffunction name="blah">
    <cfset var myFoo = 123>
    <cfset var varNamePrefix = "my">

    <cfset var bar = Evaluate("#varNamePrefix#Foo")>

    <cfreturn bar>
</cffunction>

With开发者_开发技巧 CF9, I can use local["#varNamePrefix#Foo"]. Is there a way for CF7/8 to get rid of the Evaluate() without refactoring the whole thing with var local = structNew()?


Not by documented means. Pre-CF9 there is only getPageContext().getActiveFunctionLocalScope()

<cffunction name="blah">
    <cfset var myFoo = 123>
    <cfset var varNamePrefix = "my">
    <!--- ie object.method()[keyName] syntax does not seem to be supported --->
    <cfset var localScope = getPageContext().getActiveFunctionLocalScope()>
    <cfset var bar = localScope["#varNamePrefix#Foo"]>

    <cfreturn bar>
</cffunction>
0

精彩评论

暂无评论...
验证码 换一张
取 消