cfparam'd 变量怎么可能是未定义的?

发布于 2024-12-09 04:58:43 字数 1689 浏览 0 评论 0原文

许多源通常通过 调用单个资源,但有些源使用

理想情况下,代码会查找变量 previous_state。如果传递了某些变体,则资源将尝试使用它们。

我收到这个错误:

变量 PREVIOUS_STATE 未定义。

该行记录指向该代码块中的

<cfparam    name=       "previous_state"
            default=    "" />

<cfif   isSimpleValue( previous_state )
        and len( previous_state ) eq 0>
    <cfset  previous_state= previousState />

</cfif>

我的问题是 previous_state 如何未定义?

我可以在应用程序中复制它,但它是一个使用线程的相当复杂的代码链。也许引用被垃圾收集器吃掉了?

我无法在简单的代码段中复制它。我尝试使用 returnType= "void" 将变量设置为函数的返回值,但 似乎将其重置为空字符串。

这是完整的代码上下文。我删除了不相关的变量等。

// Page
oComponent.foo();

// Component.foo()
<cfset  var local=  {
    previous_state= QueryNew( "foo" , "varchar" )

} />

<cfthread   name=   "foo_#createUUID()#"
            previousState=  "#local.previous_state#">
    <!---   Module does unrelated things... --->
    <cfmodule   template=   "some_module.cfm">
        <cfoutput>
        // unrelated things

        <cfparam    name=       "previous_state"
                    default=    "" />

        <!--- Next line is throwing error. --->
        <cfif   isSimpleValue( previous_state )
                and len( previous_state ) eq 0>
            <cfset  previous_state= previousState />

        </cfif>

        </cfoutput>

    </cfmodule>

</cfthread>

我现在认为 cfparam 正在尝试使用在此代码执行时不再存在的作用域。

A lot of sources call a single resource, typically through <cfthread ..>, but some use <cfinclude ..>.

Ideally, the code looks for the variable previous_state. If some variants are passed, then the resource will attempt to use them.

I received this error:

Variable PREVIOUS_STATE is undefined.

The line record points to the <cfif ..> in this chunk of code.

<cfparam    name=       "previous_state"
            default=    "" />

<cfif   isSimpleValue( previous_state )
        and len( previous_state ) eq 0>
    <cfset  previous_state= previousState />

</cfif>

My question is how can previous_state be undefined?

I can duplicate it in the application, but it's a fairly complex chain of code using threads. Perhaps the reference was eaten by the garbage collector?

I'm having trouble duplicating it in a simple code segment. I've tried setting the variable to the return of a function with returnType= "void", but <cfparam ..> seems to reset it to an empty string.

Here's the full code context. I removed the unrelated vars and such.

// Page
oComponent.foo();

// Component.foo()
<cfset  var local=  {
    previous_state= QueryNew( "foo" , "varchar" )

} />

<cfthread   name=   "foo_#createUUID()#"
            previousState=  "#local.previous_state#">
    <!---   Module does unrelated things... --->
    <cfmodule   template=   "some_module.cfm">
        <cfoutput>
        // unrelated things

        <cfparam    name=       "previous_state"
                    default=    "" />

        <!--- Next line is throwing error. --->
        <cfif   isSimpleValue( previous_state )
                and len( previous_state ) eq 0>
            <cfset  previous_state= previousState />

        </cfif>

        </cfoutput>

    </cfmodule>

</cfthread>

I'm now thinking cfparam is trying to use a scope that no longer exists by the time this code executes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月下凄凉 2024-12-16 04:58:43

由于代码位于 CFTHREAD 标记内,我认为您应该将 previous_state 作为 CFTHREAD 属性传递,例如:

<cfparam name="previous_state" default="" />

    <CFTHREAD previous_state = previous_state
    previousState=  "#local.previous_state#">

    <cfif  isSimpleValue( ATTRIBUTES.previous_state  ) ........

    </CFTHREAD>

引用 CF 文档:

“属性范围包含传递到范围的属性,并且仅在线程内且仅在线程的生命周期内可用。”

As the code is within a CFTHREAD tag I thing you should be passing previous_state as a CFTHREAD attribute, such as:

<cfparam name="previous_state" default="" />

    <CFTHREAD previous_state = previous_state
    previousState=  "#local.previous_state#">

    <cfif  isSimpleValue( ATTRIBUTES.previous_state  ) ........

    </CFTHREAD>

To quote the CF Docs:

"The Attributes scope contains attributes that are passed to the scope, and is available only within the thread and only for the life of the thread."

深巷少女 2024-12-16 04:58:43

要使 previous_state 未定义,它需要为 null。您需要做类似的事情

<cfif isNull(previous_state)>true</cfif>

来证明这一点,请尝试以下操作

<cfset previous_state = "" />
<!--- Change to set previous_state --->
<cfset previous_state = javacast( "null", previous_state ) />

<cfparam name="previous_state" default="" />

<cfif isSimpleValue( previous_state ) and len( previous_state ) eq 0 >
    <cfset previous_state = previousState />
</cfif>

For previous_state to be undefined it would need to be null. You would need to do something like

<cfif isNull(previous_state)>true</cfif>

To prove this try the following

<cfset previous_state = "" />
<!--- Change to set previous_state --->
<cfset previous_state = javacast( "null", previous_state ) />

<cfparam name="previous_state" default="" />

<cfif isSimpleValue( previous_state ) and len( previous_state ) eq 0 >
    <cfset previous_state = previousState />
</cfif>
吃兔兔 2024-12-16 04:58:43

确保你的变量范围正确,并且上面的示例中有一个拼写错误。我在 ACF9.0.1 和 Railo 3.3.1.000 上运行此代码时没有遇到问题

<cfparam    name=       "previous_state"
            default=    "" />

<cfdump var="#previous_state#">

Make sure you scope your variables properly and your example above has a typo in it. I'm not having an issue running this code on both ACF9.0.1 and Railo 3.3.1.000

<cfparam    name=       "previous_state"
            default=    "" />

<cfdump var="#previous_state#">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文