Note also that you may find, as many have in the past, that it's irritating having to explicitly var scope each and every variable you may be using within a function. The most common way of avoiding having to do that is to var scope a struct and then use it religiously to contain all of your variables you use:
<cfset var local = structnew()> <cfset local.timer1 = gettickcount()> <cfloop array="#arguments.blah#" index="local.i"> ... </cfloop> <cfset local.timer2 = gettickcount()> <cfset local.elapsed = local.timer2 - local.timer1> Etc. On Wed, Jul 11, 2012 at 6:00 PM, Matthew Woodward <[email protected]>wrote: > On Wed, Jul 11, 2012 at 7:18 AM, Jason King <[email protected]>wrote: > >> However, at the bottom, the 'returnString' variable is not called or >> set with 'var'. >> > > That's because var is a declaration keyword. You only do that once to keep > that variable local in scope to the function within which it's declared. > > Question. Once you 'var' scope a variable in a function, do any calls >> to that variable name within that function default to the 'var' scoped >> one? >> > > Yes. > > >> >> I'm just wondering how that would work. Within a parent document, you >> have a variable 'returnString', and that parent document calls a >> function that has a 'var' scoped variable named 'returnString' as >> well. Which one gets used when the function calls 'returnString' ?? >> > > Completely depends on what you set the return variable name to in the > caller. > > <cfset foo = 1 /> > > <cfset foo = someCFC.someMethod() /> > > At that point foo is overwritten by whatever is returned from the CFC > method. The variable *names* do not leak out of the CFC method. > > > -- > Matthew Woodward > [email protected] > http://blog.mattwoodward.com > identi.ca / Twitter: @mpwoodward > > Please do not send me proprietary file formats such as Word, PowerPoint, > etc. as attachments. > http://www.gnu.org/philosophy/no-word-attachments.html > > -- > online documentation: http://openbd.org/manual/ > http://groups.google.com/group/openbd?hl=en > -- online documentation: http://openbd.org/manual/ http://groups.google.com/group/openbd?hl=en
