Someone was on the dot when he mentioned the scope bit as the root cause. Clearly, the first scope to check for existence of a variable is arguments. Then comes var scope, then ... I don't know but there will be a definite sequence. Each scope is exactly like the local structure Jason is using. So I would find it a redundant container other than it helps one avoid trying to remember this scope sequence or worry about name collisions.
One should and can avoid this mess by simply always using the scope prefix and even better if you minimise colliding names. The only place I find a challenge is when I need to use a var scope variable. Because I don't think we can do this(for instance): <cfloop from=1 to="#var.size#" index=var.j> ... </cfloop> The "var.xyz" syntax is used here and seems it is not supported to pick up the value and assign to lhs or declare a new variable. np np On 19-Nov-2015 3:51 am, "'Alan Holden' via Open BlueDragon" < [email protected]> wrote: > Sure, you're creating and/or referencing variables within a cf tag or > script. They're just variables in there. > > The use of # characters is to render the value of a cf variable *where a > string is typically used*: > > Examples: > > <cfset myFormatPreference = "MM/DD/YYYY" /> > <cfset myDateString = dateFormat(now(),myFormatPreference) /> > > <cfset myServerURL = "http://akh.com" <http://akh.com> /> > <cfhttp method="get" url="#myServerURL #" result="myWebContent" /> > > <html> > <body> > <cfoutput> > <p>Today's date is #myDateString #</p> > > Here's the content from my server:</br> > #myWebContent# > > <p> > Here's one Octothorp character inside the cfoutput tags: ## > </p> > </cfoutput> > > <p> > Here's one Octothorp character outside the cfoutput tags: # > </p> > </body> > </html> > > HTH, > Al > > On 11/18/2015 1:22 PM, Jason King wrote: > > I didn't realize you could do that.... > > On Wed, Nov 18, 2015 at 3:21 PM, 'Alan Holden' via Open BlueDragon < > [email protected]> wrote: > >> Speaking of simplification, seems to me that: >> <cfset local.test = "#raguments.test#"> >> Could just be: >> <cfset local.test = raguments.test /> >> >> (probably a typo or 'arguments', but I just pasted what was there) >> Al >> >> >> On 11/18/2015 8:59 AM, Jason King wrote: >> >> Yep, naming conventions were from me trying to simplify the problem and >> remove unneeded code. >> >> One approach I've used in the past for longer functions is to declare a >> struct named 'local' and assign all vars local to the function to this >> struct. >> >> <cfset var local = StructNew()> >> <cfset local.test = "#raguments.test#"> >> >> Should I just do this for everything? >> >> On Wed, Nov 18, 2015 at 10:16 AM, Marcus F <[email protected]> wrote: >> >>> Here's how I understand it (I may be off, someone correct me if I am, >>> please). >>> >>> They are different scopes, but OpenBD traverses scopes to see if it can >>> access a variable for you, so when you set the testVar it checks the scopes >>> and sets arguments.testVar >>> >>> A co-worker tells me that if you var testVar, it would create a local >>> testVar variable that you can reference separately. >>> >>> Granted, you should never be using names that can be confused in this >>> way, but I assume it's just test code. >>> >>> >>> On Wednesday, November 18, 2015 at 10:52:04 AM UTC-5, Jason Allen wrote: >>>> >>>> This is what's confusing me. >>>> >>>> If you declare an argument, say 'test' and I pass it into the function, >>>> isn't it's value 'argument.test'? >>>> >>>> If I then declare a simple variable 'test', isn't a different variable >>>> than 'arguments.test'? >>>> >>>> Or, when declaring a function, do I not need to use the 'argument.' >>>> prefix to reference it? >>>> >>>> Basically, is 'arguments.test' the same as 'test'? >>>> >>>> If so, it's new to me. I thought they were different. >>>> >>>> On Wed, Nov 18, 2015 at 6:40 AM, Marcus F <[email protected]> wrote: >>>> >>>>> Because you're setting the variable to a blank value. >>>>> >>>>> The variable name is testVar, and you specifically set <cfset testVar >>>>> = ""> before checking the value. >>>>> >>>>> Name it something else and it'll work. >>>>> >>>>> >>>>> On Tuesday, November 17, 2015 at 6:33:12 PM UTC-5, Jason Allen wrote: >>>>>> >>>>>> *Hi Guys, * >>>>>> >>>>>> *I'm getting what I think is strange behavior. * >>>>>> >>>>>> *I'm building a function. * >>>>>> >>>>>> * <cffunction name="testFunction" returntype="struct" output="no" >>>>>> access="remote" returnformat="json">* >>>>>> >>>>>> * <cfargument name="testVar" type="numeric" required="false" >>>>>> default="" hint="" />* >>>>>> * <cfset var test=StructNew()>* >>>>>> * <cfset test.originalTest = "#arguments.testVar#">* >>>>>> * <cfset test.originalTestTrim = "#trim(arguments.testVar)#">* >>>>>> * <cfset test.testVar = "">* >>>>>> * <cfset testVar = "">* >>>>>> * <!--- test --->* >>>>>> * <cfif trim(arguments.testVar) eq ''>* >>>>>> * <cfset testVar = "woops">* >>>>>> * </cfif>* >>>>>> >>>>>> * <cfset test.testVar = "#testVar#">* >>>>>> * <cfsetting showdebugoutput="false" />* >>>>>> >>>>>> * <cfreturn test>* >>>>>> >>>>>> * </cffunction>* >>>>>> >>>>>> >>>>>> *The part I'm having trouble with is* >>>>>> >>>>>> *<cfif trim(arguments.testVar) eq ''>* >>>>>> >>>>>> *Even though I've supplied the argument 'arguments.testVar' and it is >>>>>> a recongized value (able to assign value to test.oroginalTest, * >>>>>> *the if statement is returning true and setting testVar to 'woops'. * >>>>>> >>>>>> *What am I missing? * >>>>>> >>>>> -- >>>>> -- >>>>> online documentation: http://openbd.org/manual/ >>>>> http://groups.google.com/group/openbd?hl=en >>>>> >>>>> --- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Open BlueDragon" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> -- >>> -- >>> online documentation: http://openbd.org/manual/ >>> http://groups.google.com/group/openbd?hl=en >>> >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "Open BlueDragon" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- >> -- >> online documentation: http://openbd.org/manual/ >> http://groups.google.com/group/openbd?hl=en >> >> --- >> You received this message because you are subscribed to the Google Groups >> "Open BlueDragon" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> >> >> -- >> -- >> online documentation: http://openbd.org/manual/ >> http://groups.google.com/group/openbd?hl=en >> >> --- >> You received this message because you are subscribed to the Google Groups >> "Open BlueDragon" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > -- > online documentation: http://openbd.org/manual/ > http://groups.google.com/group/openbd?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "Open BlueDragon" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > > > -- > -- > online documentation: http://openbd.org/manual/ > http://groups.google.com/group/openbd?hl=en > > --- > You received this message because you are subscribed to the Google Groups > "Open BlueDragon" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- online documentation: http://openbd.org/manual/ http://groups.google.com/group/openbd?hl=en --- You received this message because you are subscribed to the Google Groups "Open BlueDragon" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
