Empowering Smart Business (sm)

UDFs: getVariableScopeList()

The future of your business is an open road, JPG image (20.8kb)

getVariableScopeList()

Function that determines in which scopes a variable is defined. Does not check named scopes (i.e., query names, etc.).

<CFSCRIPT>
/**
 * Function that determines in which scopes a variable is defined.  Does not
 * check named scopes (i.e., query names, etc.).
 * 
 * @param locVar	The name of the variable. (Required)
 * @return			Returns a list of scopes.  Blank if none.
 * @author Mosh Teitelbaum (mosh.teitelbaum@evoch.com)
 * @version 1, February 24, 2004
 */
function getVariableScopeList(locVar) {
  var baseScopeList = "VARIABLES,CGI,FILE,URL,FORM,COOKIE,CLIENT,APPLICATION,SESSION,SERVER,REQUEST,CFHTTP,CALLER,ATTRIBUTES,ERROR,CFCATCH,CFFTP";
  var scopeList = "";
  var listEle = "";
  var cnt = 1;

  while ( cnt LTE ListLen(baseScopeList) ) {
    // Get current list element
    listEle = ListGetAt(baseScopeList, cnt);

    // Check for existence within current scope.  CGI is a special case
    if (listEle is "CGI" AND structKeyExists(cgi, locVar)) {
        scopeList = ListAppend(scopeList, listEle);
    } else if (not listEle is "CGI" AND IsDefined("#listEle#.#locVar#")) {
        scopeList = ListAppend(scopeList, listEle);
    }

    // Increment counter
    cnt = cnt + 1;
  }

  return scopeList;
}
</CFSCRIPT>