Home arrow ColdFusion arrow Page 5 - Everything You Must Know About ColdFusion Variables

Everything You Must Know About ColdFusion Variables

Understanding ColdFusion variables and logic is vital to being able to program in the language. In this tutorial, Jay's second covering ColdFusion, you will learn about the types of ColdFusion variables and how to use them.

Author Info:
By: Jayaram Krishnaswamy
Rating: 4 stars4 stars4 stars4 stars4 stars / 25
August 15, 2005
  1. · Everything You Must Know About ColdFusion Variables
  2. · Developing ColdFusion Content
  3. · Variable definition with CFSET tag
  4. · Variable by assigning statements in CFSCRIPT
  5. · Scope of a variable
  6. · Data Type Category of Variables
  7. · How do we name a variable?

print this article

Everything You Must Know About ColdFusion Variables - Scope of a variable
(Page 5 of 7 )

In general, scope refers to the time during which the variable persists (and therefore can be accessed); that is its lifetime. Some variables may last only for the duration of a session, some may last until the application is terminated. Some variables may be available in a certain portion of a program, generally inside a function, and not available outside the function. Compared to the scope of a variable in JavaScript, ColdFusion has more fine grained scope definition for its variables.

Scopes and their types

The scope types are listed here (taken directly from the Macromedia website) but their usage will be discussed at appropriate times when they are encountered. ColdFusion checks the scope of variables in a certain order to find the variable, and the best practice is to use the dot notation to specify the scope of a variable. For example, for a variable MyVariable in the context of a Form to be used outside the form, use Form.MyVariable to access the variable. This is very similar to JavaScript's access to control fields on a form. Both Form.MyVariable and Form["MyVariable"] are accepted notations to access MyVariable.

  • Variables; local
  • Form
  • URL
  • Attributes
  • Caller
  • This Tag
  • Request
  • CGI
  • Cookie
  • Client
  • Session
  • Application
  • Server
  • Flash
  • Arguments
  • This
  • Function Call

Here is a CFM file that shows examples of two of the scopes from the above list, Variables and Server. Server has a set of built in variables which can be accessed as shown.

<!--- Scope: Variables and Server scope--->
WriteOutput("Version of ColdFusion used in this tutorial is:<br/> ");
WriteOutput("The author of this tutorial is: <br/>");

The server processed file in the browser is shown in this picture

blog comments powered by Disqus

- Adobe ColdFusion Just Got More RAD
- How to Access a SQL Anywhere Database with C...
- CFXML: Probing XMLDOM in ColdFusion
- Creating a Web Service with ColdFusion: the ...
- CFAjax: What it is and How to Use it
- Querying SQL 2000 Server from ColdFusion
- Introduction to ColdFusion Markup Language, ...
- Introduction to ColdFusion Markup Language
- Databases and Dreamweaver MX 2004, concluded
- Databases and Dreamweaver MX 2004
- Welcome to Coldfusion MX 6.1, concluded
- Welcome to Coldfusion MX 6.1
- What You Must Know About ColdFusion Flow-Con...
- What You Must Know About Operators in ColdFu...
- Everything You Must Know About ColdFusion Va...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials