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];
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson