Adobe COLDFUSION 9 Manual page 160

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Function variable
functionName
argName1...
The body of the function definition must be in curly brackets, even if it is empty.
The following two statements are allowed only in function definitions:
Statement
var
variableName = expression;
return
expression;
A simple CFScript example
The following example function adds the two arguments and returns the result:
<cfscript>
function Sum(a,b) {
var sum = a + b;
return sum;
}
</cfscript>
In this example, a single line declares the function variable and uses an expression to set it to the value that it returns.
This function can be simplified so that it does not use a function variable, as follows:
function MySum(a,b) {Return a + b;}
Always use curly brackets around the function definition body, even if it is a single statement.
Note: ColdFusion does not COPY any of the function arguments into the local scope of a function. However, if an
unscoped variable is called, it is searched first in argument scope and then local scope.
Description
The name of the function. You cannot use the name of a standard ColdFusion function or any name that
starts with "cf". You cannot use the same name for two different function definitions. Function names
cannot include periods.
Names of the arguments required by the function. The number of arguments passed into the function
must equal or exceed the number of arguments in the parentheses at the start of the function definition.
If the calling page omits any of the required arguments, ColdFusion generates a mismatched argument
count error.
Description
Creates and initializes a variable that is local to the function (function variable). This variable
has meaning only inside the function and is not saved between calls to the function. It has
precedence in the function body over any variables with the same name that exist in any
other scopes. You never prefix a function variable with a scope identifier, and the name
cannot include periods. The initial value of the variable is the result of evaluating the
expression. The expression can be any valid ColdFusion expression, including a constant or
even another UDF.
All
var
statements must be at the top of the function declaration, before any other
statements. Initialize all variables when you declare them. You cannot use the same name
for a function variable and an argument.
Each var statement can initialize only one variable.
Use the var statement to initialize all function-only variables, including loop counters and
temporary variables.
Evaluates expression (which can be a variable), returns its value to the page that called the
function, and exits the function. You can return any ColdFusion variable type.
Last updated 8/5/2010
155

Advertisement

Table of Contents
loading

Table of Contents