User Guide

Table Of Contents
Working with arguments and variables in functions 181
About the Arguments scope
All function arguments exist in their own scope, the Arguments scope.
The Arguments scope exists for the life of a function call. When the function returns, the scope
and its variables are destroyed.
However, destroying the Argument scope does not destroy variables, such as structures or query
objects, that ColdFusion passes to the function by reference. The variables on the calling page
that you use as function arguments continue to exist; if the function changes the argument value,
the variable in the calling page reflects the changed value.
The Arguments scope is special, in that you can treat the scope as either an array or a structure.
This dual nature of the Arguments scope is useful because it makes it easy to use arguments in any
of the following circumstances:
You define the function using CFScript.
You define the function using the cffunction tag.
You pass arguments using argument name=value format.
You pass arguments as values only.
The function takes optional, undeclared arguments.
The following sections describe the general rules for using the Arguments scope as an array and a
structure. For more information on using the Arguments scope in functions defined using
CFScript, see “Using the Arguments scope in CFScript” on page 184. For more information on
using the Arguments scope in functions defined using the
cffunction tag, see “Using the
Arguments scope in cffunction definitions on page 184.
The contents of the Arguments scope
The following rules apply to the Arguments scope and its contents:
The scope contains all the arguments passed into a function.
If you use cffunction to define the function, the scope always contains an entry “slot” for
each declared argument, even if you do not pass the argument to the function when you call it.
If you do not pass a declared (optional) argument, the scope entry for that argument is empty.
When you call a function that you defined using CFScript, you must pass the function a value
for each argument declared in the function definition. Therefore, the Arguments scope for a
CFScript call does not have empty slots.
The following example shows these rules. Assume that you have a function declared, as follows:
<cffunction name="TestFunction">
<cfargument name="Arg1" >
<cfargument name="Arg2">
</cffunction>
You can call this function with a single argument, as in the following line:
<cfset TestFunction(1)>