Not yet rated

Problem

Prior to ColdFusion 9, it was not always easy to <cfdump /> a variable when using <cfscript />.

Solution

Create a function or a utility component which you can then call from cfscript. Using the function, you can pass in "true" to stop the code execution anywhere you place the function call. This is useful for debugging chunks of code with a lot of conditional logic.

Detailed explanation

<cfset userArray = arraynew(2)>
<cfset userArray[1][1] = "Barbara">
<cfset userArray[1][2] = "Simmons">
<cfset userArray[1][3] = "barbara.simmons@aheadadvertising.com">

<cfset userArray[2][1] = "Denis">
<cfset userArray[2][2] = "Bagley">
<cfset userArray[2][3] = "denis.bagley@aheadadvertising.com">

<cfset userArray[3][1] = "John">
<cfset userArray[3][2] = "Bristol">
<cfset userArray[3][3] = "john.bristol@aheadadvertising.com">

<!--- ColdFusion tag dump --->
<cfdump var="#userArray#">

<cfscript>
    
    // CF9 only
    writeDump(userArray);
    
    // ColdFusion dump using a function
    myDump(userArray);
    
    // stop execution while in a loop
    for(i = 1; i lte arraylen(userArray); i++)
    {
        myDump(userArray[i], true);
    }
    
</cfscript>

<!--- add this to your Dreamweaver SNIPPETS panel, or use as a utility via a CF component --->
<cffunction name="myDump">
    <cfargument name="myValue" type="any" required="yes">
    <cfargument name="myAbort" type="boolean" required="no" default="false">
    
    <cfdump var="#ARGUMENTS.myValue#">
    <!--- if you call this function in a loop, pass in "myAbort" as true --->
    <cfif ARGUMENTS.myAbort eq true>
        <cfabort>
    </cfif>
    
</cffunction>





+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes