User Guide

Table Of Contents
CFC variables and scope 229
In this example, the callGreetMe.cfm page does the following:
1.
Sets the MyName variable in its Variables scope to Wilson.
2.
Displays the Variables.MyName value.
3.
Calls the greetMe CFC and passes its Variables scope as a parameter.
4.
Displays the value returned by the greetMe CFC.
5.
Displays the Variables.MyName value.
6.
Invokes the VarScopeInCfc method, which displays the value of Variables.MyName within the
CFC.
When you browse the callGreetMe.cfm page, the following appears:
Before invoking the CFC, Variables.Myname is: Wilson.
Passing Variables scope to hello method. It returns: Hello Wilson.
After invoking the CFC, Variables.Myname is: Wilson.
Within the VarScopeInCfc method, Variables.MyName is: Tuckerman
The Arguments scope
The Arguments scope exists only in a method, and is not available outside the method. The scope
contains the variables that you passed into the method, including variables that you passed in the
following ways:
As named attributes to the cfinvoke tag
In the cfargumentcollection attribute of the cfinvoke tag
In cfinvokeargument tags
As attributes or parameters passed into the method when the method is invoked as a web
service, by Flash Remoting, as a direct URL, or by submitting a form
You can access variables in the Arguments scope using structure notation
(
Arguments.variablename), or array notation (Arguments[1] or
Arguments["variablename"]).
The Arguments scope does not persist between calls to CFC methods.
Variables in the Arguments scope are available to pages included by the method.
Other variable scopes
A CFC shares the Form, URL, Request, CGI, Cookie, Client, Session, Application, Server, and
Flash scopes with the calling page. Variables in these scopes are also available to all pages that are
included by a CFC. These variables do not have any behavior that is specific to CFCs.
Function local variables
Variables that you declare with the Var keyword inside a
cffunction tag or CFScript function
definition are available only in the method in which they are defined, and only last from the time
the method is invoked until it returns the result. You cannot use the Var keyword outside of
function definitions.