Localscope app 30 second video7/23/2023 I didn’t find any documentation about it somewhere. Also the error means that "var Argu2" does not isolates Argu2 from the other scopes (eg Arguments) that’s why it conflicts with Arguments.Argu2 and gives the error. What I understand of this error is that var is not really a scope, and it’s not indentical to local. The error happens only in case the var variable has the same name (Argu2) with the argument variable Argu2, and although when doing exactly the same, using local, there is no problem. Use local to define a local variable with same name. Running the code I get an error message !!! The error is:ĪRGU2 is already defined in argument scope. Today I faced a problem (bug?) on the use of var, which is exactly on the subject of the discussion here, and which shows that var is not practically indentical to local scope.Īs you see I just declare two variables, and I do it in the first case using the local scope and in second case using the var. This limitation has been removed in ColdFusion Centaur (and I actually have mixed feelings about this, but so be it). The “var” keyword used to only be supported at the top of functions and methods, so all local variables had to be defined upfront. And yes, if you have a variable named “local” it’ll still work, the variable will just become LOCAL.local, and as the LOCAL scope is in the default evaluation chain it’ll just work. It’s clean, it’s simple, it’s intuitive, and it’s fully backwards compatible. Variables with the var prefix are now automatically defined in the LOCAL scope. Look at the following two statements:īoth of these code snippets do the exact same thing. Here is the same local variable set above, but using the LOCAL scope instead of var:īut what if you do indeed use var? Well, it’ll just work. And so, when creating user defined functions or ColdFusion Component methods, the rule has always been to always prefix local variables with “var”.īut what exactly is a var variable? What scope is it in? And how is it accessed using explicit scope notation? The answers to these questions are somewhat unclear, partially because the local var scope is not used like any other ColdFusion scope which is always designated by using a scope prefix (VARIABLES.myVariable, FORM.myVariable, SESSION.mayVariable, etc.).ĬoldFusion Centaur simplifies the use of local scopes (without breaking existing code) by explicitly defining a local scope that it intuitively named LOCAL. The second variable does not use var, and as such is not local, and variable conflicts can indeed occur. The first variable uses the var keyword to ensure that the variable is local to the function, and if the same variable name existed elsewhere it won’t be overwritten. In the above snippet, two variables are created. ColdFusion developers have long known to ensure that local variables remain local by using the “var” keyword to define them.
0 Comments
Leave a Reply. |