– Common Function Library Project

Dump(var [, expand] [, label] [, top])

Last updated October 16, 2002

Version: 2 | Requires: ColdFusion MX | Library: CFMLLib

Rated 2 time(s). Average Rating: 4.5

Mimics the cfdump tag, but adds new "top" attribute.

Return Values:
Returns a string.


view plain print about
<cfset x = arraynew(1)>
<cfloop index="y" from=1 to=200>
    <cfset x[y] = randRange(1,1000)>

dump(var=x,label="The Array X",top=10);


Name Description Required
var The variable to dump. Yes
expand Expand output. Defaults to true. No
label Label for dump. No
top Restricts output based on type. If array or query, top will represent the number of rows to show. If structure, will show this many keys. No

Full UDF Source:

view plain print about
 Mimics the cfdump tag.
 Updated for final cfmx var scope - also, we only redo var if size bigger than top.
 @param var      The variable to dump. (Required)
 @param expand      Expand output. Defaults to true. (Optional)
 @param label      Label for dump. (Optional)
 @param top      Restricts output based on type. If array or query, top will represent the number of rows to show. If structure, will show this many keys. (Optional)
 @return Returns a string. 
 @author Raymond Camden ( 
 @version 2, October 16, 2002 

<cffunction name="dump" returnType="string">
    <cfargument name="var" type="any" required="true">
    <cfargument name="expand" type="boolean" required="false" default="true">
    <cfargument name="label" type="string" required="false" default="">
    <cfargument name="top" type="numeric" required="false">
    <!--- var --->
    <cfset var type = "">
    <cfset var tempArray = arrayNew(1)>
    <cfset var temp_x = 1>
    <cfset var tempStruct = structNew()>
    <cfset var orderedKeys = "">
    <cfset var tempQuery = queryNew("")>
    <cfset var col = "">
    <!--- do filtering if top ---->
    <cfif isDefined("top")>
        <cfif isArray(var)>
            <cfset type = "array">
        <cfif isStruct(var)>
            <cfset type="struct">
        <cfif isQuery(var)>
            <cfset type="query">
        <cfswitch expression="#type#">
            <cfcase value="array">
                <cfif arrayLen(var) gt top>
                    <cfloop index="temp_x" from=1 to="#Min(arrayLen(var),top)#">
                        <cfset tempArray[temp_x] = var[temp_x]>
                    <cfset var = tempArray>
            <cfcase value="struct">
                <cfif listLen(structKeyList(var)) gt top>
                    <cfset orderedKeys = listSort(structKeyList(var),"text")>
                    <cfloop index="temp_x" from=1 to="#Min(listLen(orderedKeys),top)#">
                        <cfset tempStruct[listGetAt(orderedKeys,temp_x)] = var[listGetAt(orderedKeys,temp_x)]>
                    <cfset var = tempStruct>
            <cfcase value="query">
                <cfif var.recordCount gt top>
                    <cfset tempQuery = queryNew(var.columnList)>
                    <cfloop index="temp_x" from=1 to="#min(var.recordCount,top)#">
                        <cfset queryAddRow(tempQuery)>
                        <cfloop index="col" list="#var.columnList#">
                            <cfset querySetCell(tempQuery,col,var[col][temp_x])>
                    <cfset var = tempQuery>
    <cfdump var="#var#" expand="#expand#" label="#label#">
blog comments powered by Disqus


Latest Additions

CF Ninja CF Ninja added
15 day(s) ago

Stephen Withington Stephen Withington added
15 day(s) ago

Adam Cameron Adam Cameron added
a while ago

Ray Ford Ray Ford added
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 48 time(s)

Barney Boisvert indentXml
Rated 5.0, 12 time(s)

Rachel Lehman deAccent
Rated 5.0, 9 time(s)

Darwan Leonardo Sitepu splitNumber
Rated 5.0, 8 time(s)

Created by Raymond Camden / Design by Justin Johnson