User Guide

Table Of Contents
Working with arguments and variables in functions 183
<cfargument name="Arg2">
<cfloop index="i" from="1" to="#ArrayLen(Arguments)#">
<cfoutput>Argument #i#: #Arguments[i]#<br></cfoutput>
</cfloop>
</cffunction>
<strong>One Unnamed argument</strong><br>
<cfset TestFunction(1)>
<strong>Two Unnamed arguments</strong><br>
<cfset TestFunction(1, 2)>
<strong>Three Unnamed arguments</strong><br>
<cfset TestFunction(1, 2, 3)>
<strong>Arg1:</strong><br>
<cfset TestFunction(Arg1=8)>
<strong>Arg2:</strong><br>
<cfset TestFunction(Arg2=9)>
<strong>Arg1=8, Arg2=9:</strong><br>
<cfset TestFunction(Arg1=8, Arg2=9)>
<strong>Arg2=6, Arg1=7</strong><br>
<cfset TestFunction(Arg2=6, Arg1=7)>
<strong>Arg1=8, Arg2=9, Arg3=10:</strong><br>
<cfset TestFunction(Arg1=8, Arg2=9, Arg3=10)>
<strong>Arg2=6, Arg3=99, Arg1=7</strong><br>
<cfset TestFunction(Arg2=6, Arg3=99, Arg1=7)>
Note: Although you can use the Arguments scope as an array, the
IsArray(Arguments) function
always returns false and the cfdump tag displays the scope as a structure.
Using the Arguments scope as a structure
The following rule applies when referencing Arguments scope as a structure:
Use the argument names as structure keys. For example, if your function definition includes a
Principal argument, refer to the argument as Arguments.Principal.
The following rules are also true, but avoid writing code that uses them. To ensure program clarity,
only use the Arguments structure for arguments that you name in the function definition. Use the
Arguments scope as an array for optional arguments that you do not declare in the function
definition.
If the function can take unnamed optional arguments, use array notation to reference the
unnamed arguments. For example, if the function declaration includes two named arguments
and you call the function with three arguments, refer to the third argument as Arguments[3].
To determine if an unnamed optional argument exists, use the
StructKeyExists function; for
example,
structKeyExists(Arguments,"3").
If you do not name an optional argument in the function definition, but do use a name for it
in the function call, use the name specified in the function call For example, if you have an
unnamed optional argument and call the function using the name myOptArg for the
argument, you can refer to the argument as Arguments.myOptArg in the function body. This
usage, however, is poor programming practice, as it makes the function definition contents
depend on variable names in the code that calls the function.