Does it always search of the variable is not scoped (when calling it) even
if you do a cfset at the top of the page?  Or does it automagically know it
is in the Variables scope?

Eric

-----Original Message-----
From: Eric Cobb [mailto:cft...@ecartech.com] 
Sent: Thursday, May 19, 2011 07:47 AM
To: cf-talk
Subject: Re: scoping


That's kinda backwards....

If you don't specify a scope in your cfset statement, then CF will always
put it in the VARIABLES scope.  But, if you don't specify a scope when
calling the variable (in your cfoutput), then CF will have to hunt down the
variable to determine which scope it's in.

http://www.cfgears.com/index.cfm/2010/9/22/The-importance-of-proper-variable
-scoping

Thanks,

Eric Cobb
ECAR Technologies, LLC
http://www.ecartech.com
http://www.cfgears.com


On 5/19/2011 2:55 AM, Dominic Watson wrote:
> Curiously, I do it the exact opposite way:
>
> <cfset variables.myVariable = "fubar" />  <!--- ensure that I am 
> setting in the variables scope, because there could be a 'myVariable'
> in another scope --->
>
> <cfoutput>#myVariable#</cfoutput>  <!--- I have just guaranteed that I 
> have variables.myVariable, there is no possibility (afaik) that I 
> could be refering to another 'myVariable'. --->
>
> However, I should probably scope both.
>
> Dominic
>
> On 18 May 2011 19:26, Aaron Rouse<aaron.ro...@gmail.com>  wrote:
>> This is my outlook although I do not do something like:
>>
>> <cfset Variables.strBlah = "something" />
>>
>> instead I do:
>>
>> <cfset strBlah = "something" />
>>
>> But I always would do:
>>
>> <cfoutput>#Variables.strBlah#</cfoutput>
>>
>> or
>>
>> <cfif Variables.strBlah IS "something">
>>
>> Seems to me that is what the original OP is asking about but perhaps 
>> I am reading too much into it based upon what I do.  This is all in 
>> reference to just straight CFM pages.
>>
>> On Wed, May 18, 2011 at 12:40 PM, Maureen<mamamaur...@gmail.com>  wrote:
>>
>>> ALWAYS SCOPE!!!!!
>>>
>>> Especially if someone else might have to maintain the code someday.
>>>
>>> On Wed, May 18, 2011 at 9:51 AM, Eric Roberts 
>>> <ow...@threeravensconsulting.com>  wrote:
>>>> We had a discussion at work as to whether or not we should scope 
>>>> local
>>> vars
>>>> with the "variables." scope since that is implied in a cfset.  One 
>>>> camp
>>> says
>>>> it is not needed because of the implicit scoping when using 
>>>> cfset...the other camp says it is better to tack on "variables." 
>>>> and make it explicit for security and readability.  Any thoughts?
>>>>
>>>> Er
>>>
>>
> 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:344708
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to