"var" defines a variable as local to a given method.  It means that the
variable will be destroyed when the call to the method is over and won't
conflict with the name of other local or instance variables.  Always be sure
to use the var keyword when creating variables that will only be used inside
a method -- I can't emphasize enough how important and how easy to forget to
do it is.

The "variables" scope in a CFC designates a variable as private to the
instance (warning: if you are coming from a java world, it's not truly
private, but you can think of it that way) of the CFC.  It will live as long
as the instance lives, and is available to all methods inside the CFC.  In
general, use the variables scope whenever you need to create instance data.

The "this" scope is a reference to the public scope of the CFC.  It also
lives as long as the instance and is available to all methods inside the
CFC, but in addition it is available to the calling page as a member
variable (behaves as if it's a key in the struct that is the CFC instance).
In general, avoid use of the this scope because it makes what should be
"private" data into "public" data.

HTH,

 - Nathan


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Troy Simpson
> Sent: Tuesday, February 10, 2004 9:38 AM
> To: [EMAIL PROTECTED]
> Subject: [CFCDev] How should I define variable in a CFC?
>
>
> All,
>
> I have been away from coldfusion for about a year or so and now need to
> get back into in.  I am using ColdFusion MX for this project that I am
> working on.  I need some clarification if possible.
>
> How should I define variables in a CFC and why?
> What is the difference between the three?
>
> <cfcomponent>
>    <cfset var dsn = "DataSourceName">
>    <cfset variables.dsn = "DataSourceName">
>    <cfset this.dsn = "DataSourceName">
> </cfcomponent>
>
> Thanks,
> Troy
>
> --
> Troy Simpson
>    Applications Analyst/Programmer, OCPDBA, MCSE, SCSA
> North Carolina State University Libraries
> Campus Box 7111 | Raleigh | North Carolina
> ph.919.515.3855 | fax.919.513.3330
> E-mail: [EMAIL PROTECTED]
>
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> in the message of the email.
>
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.com).
>
> An archive of the CFCDev list is available at
> www.mail-archive.com/[EMAIL PROTECTED]
>

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to