cfparam'd 变量怎么可能是未定义的?
许多源通常通过
调用单个资源,但有些源使用
。
理想情况下,代码会查找变量 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于代码位于 CFTHREAD 标记内,我认为您应该将
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: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."
要使 previous_state 未定义,它需要为 null。您需要做类似的事情
来证明这一点,请尝试以下操作
For previous_state to be undefined it would need to be null. You would need to do something like
To prove this try the following
确保你的变量范围正确,并且上面的示例中有一个拼写错误。我在 ACF9.0.1 和 Railo 3.3.1.000 上运行此代码时没有遇到问题
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