I find it help to just var one struct and then put all local variables inside that one struct. If
you follow this procedure and then later see *ANY* variable that is not prefixed with your struct
name (I use "local") then you know you have a bad variable.
Example:
<cfset var local = structNew()>
<cfloop from="1" to="10" index="local.i">...</cfloop>
<cfquery name="local.qryName">...</cfquery>
<cfset data = someCFC.getData()> <!--- BAD!! Not prefixed with "local." ---->
In some of my bigger functions where I am using 10-15 local variables, it gets to be a maintenance
nightmare to double-check that I var'ed everything. You can save yourself a ton of headache and just
use this approach.
/Cody
Brian Peddle wrote:
Thanks Everyone that was my next question index="x" ...
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Anthony Israel-Davis
Sent: Friday, July 21, 2006 1:59 PM
To: [email protected]
Subject: RE: [CFCDev] Scoping Question
Yep - most definitely. As well as any iterator variables in loops (e.g.
index="i" would need var i = ""), return variables from cffile or cfhttp
- basically anything that needs to remain function local.
These got me when I first started in on this - particularly the cfquery
one!
anthony
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Brian Peddle
Sent: Friday, July 21, 2006 10:54 AM
To: [email protected]
Subject: [CFCDev] Scoping Question
I am pretty positive this needs to be scoped but want to verify
Example CFC to return query results:
<cffunction name="getSearchOptions" access="public" output="no"
returntype="query">
<cfset var resultset = "" />
<cfquery name="resultset" >
Query here
</cfquery>
<cfreturn resultset />
</cffunction>
The resultset should be scoped right?
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of
the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.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' as the subject of the
email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.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' as the subject of the
email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.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' as the subject of the
email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]