所以现在有3种方式。
如果您使用的是 ColdFusion 9.0 或更高版本,现在有一个名为 GetFunctionCalledName() 的函数。它会返回你正在寻找的东西。
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WS7cc222be8a31a47d-6e8b7083122cebfc8f2-8000.html
或者
使用 ColdSpring 和面向方面的编程 ( http://www.coldspringframework.org/coldspring/examples/quickstart/index.cfm?page=aop ) 为您处理这个问题。
或者
使用 cfthrow 生成包含信息的堆栈跟踪:
<cffunction name="determineFunction" output="FALSE" access="public" returntype="string" hint="" >
<cfset var functionName ="" />
<cfset var i = 0 />
<cfset var stackTraceArray = "" />
<cftry>
<cfthrow />
<cfcatch type="any">
<cfset stacktraceArray = ListToArray(Replace(cfcatch.stacktrace, "at ", " | ", "All"), "|") />
<!---Rip the right rows out of the stacktrace --->
<cfloop index ="i" to="1" from="#ArrayLen(stackTraceArray)#" step="-1">
<cfif not findNoCase("runFunction", stackTraceArray[i]) or FindNoCase("determineFunction", stackTraceArray[i])>
<cfset arrayDeleteAt(stackTraceArray, i) />
</cfif>
</cfloop>
<!---Whittle down the string to the func name --->
<cfset functionName =GetToken(stacktraceArray[1], 1, ".") />
<cfset functionName =GetToken(functionName, 2, "$")/>
<cfset functionName =ReplaceNoCase(functionName, "func", "", "once")/>
<cfreturn functionName />
</cfcatch>
</cftry></cffunction>
我的建议是使用 getFunctionCalledName,或者如果不在 CF 9 ColdSpring 上,它可能会为您购买一些其他东西。