Description

Returns an array of structs. Each struct contains template name, line number, and if applicable the function name.

History

ColdFusion 10: Added this function.

Syntax

callStackGet(__)

Usage

Callstack is a snapshot of all function calls or invocations. For your ColdFusion application, callstack provides the template name, line number, and if applicable, the function name.The feature is helpful in scenarios where you want to track the recursive calls that you made. For example,

  • a.cfm does an include of b.cfm.
  • b.cfm invokes the function callStackGet at line 15.
    This results in a callstack that returns a struct that contains the template name, line number, and the function name.

Example

In this example, the factorial of a number is computed.Here,

  1. The function callStackGet is called on line 9 in function factorial in the template fact.cfm
  2. In turn, it is called from line 14 from the template fact.cfm
  3. In turn, it is called from template callfact.cfm (line 2)
  4. And so on, for other values of n
    callfact.cfm

<cftry> 
<cfinclude template="fact.cfm"> 
<cfcatch type="any"> 
<cfoutput> 
#cfcatch.message# 
<br>#cfcatch.detail# 
<br> 
</cfoutput> 
</cfcatch> 
</cftry>

fact.cfm

<cfscript> 
numeric function factorial(n) 
{ 
if(n == 1) 
{ 
writedump(callStackGet()); 
writeoutput("<br>"); 
return 1; 
} 
else 
{ 
writedump(callStackGet()); 
writeoutput("<br>"); 
return n * factorial(n - 1); 
} 
} 
factorial(5); 
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy