Home
Username:
Password:
Macromedia ColdFusion MX Tutorials

CFCs and Variables Scope / Function Local ("var") and Arguments




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

The var, V A R, keyword was added to the variable scope in CFMX 6.1. The var keyword restricts a variable to the method where it is defined only. This is usually described as function local scope. This differs from local scope because the variable is only available to the particular method where it is defined and no others. If a variable is declared using the var keyword, it must be declared inside cf function tags at the top of the method. The declaration can be below any cf argument tags, but it must be above any code in the method itself. In our var scope CFC, we can add a variable to the show scope's function that is a function local variable by adding the cf set tag. Notice that the var keyword is used in front of a variable in the unnamed scope which is also the variables scope. Even where the call to the show scopes method inside the use scopes method, if this variable is used, it will generate an error. The arguments scope is a special scope used by user defined functions and components. When a parameter is passed in to a method, either in a user defined function or a CFC, The argument scope is used to reference the variable in the body of the method. Within the method body variables in the argument scope can be accessed using either an array syntax, or structure syntax. Arguments variable scope should be used when argument variables are referenced to maintain clarity in your code. In our example we can add arguments to the show scopes method. The cf argument tag remember, can be above the declaration of the function local variable set with the var keyword. We'll create an argument called page var. Type is string, required is yes, and the default is blank. When this method is called now, an argument is required. So we'll create the page var variable, and we'll pass this value in to the method. Now, we can output the value of this argument in the show scopes method. When we browse to this page we can see the variable. If calling page variables are needed by the component, they must be passed in using arguments. ing page variables are needed by the component, they must be passed in using arguments.

Tutorial Information

Course: Macromedia ColdFusion MX
Author: Darcey Spears
SKU: 33474
ISBN: 1932072772
Release Date: 2004-03-05
Duration: 6.5 hrs / 102 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available