CFLib.org – Common Function Library Project

param(scope, varname[, value])

Last updated February 13, 2006

author

Robert Blackburn

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
This is similar to CFParam UDF, but uses structKeyExists() instead of isDefined() for slightly better performance and more easily debugged code.

Return Values:
Returns the value of the variable.

Example:

<cfset param(VARIABLES, "variablename")>
<cfset param(VARIABLES, "variablename", "testVar")>
<cfset param(URL, "variablename", "testURLVar")>
<cfset param(FORM, "variablename", "testURLVar")>

Parameters:

Name Description Required
scope Scope to check. Yes
varname Variable name to param. Yes
value Value to use. Defaults to a space. No

Full UDF Source:

/**
 * Function to duplicate the cfparam for scoped variables.
 * 
 * @param scope      Scope to check. (Required)
 * @param varname      Variable name to param. (Required)
 * @param value      Value to use. Defaults to a space. (Optional)
 * @return Returns the value of the variable. 
 * @author Robert Blackburn (skorpiun@gmail.com) 
 * @version 1, February 13, 2006 
 */
function param(scope, varname) {
    var value = "";
    
    if(arrayLen(arguments) gt 2) {
        value = arguments[3];
    }
    
    if(NOT structKeyExists(arguments.scope, arguments.varname) ) {
        arguments.scope[arguments.varname] = value;
    }
    
    return arguments.scope[arguments.varname];
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson