Can you var scope multiple variables at once in Coldfusion?

As everyone said you need to scope your variables with var or local Also as @Ben said, you can't really var scope variables like you have. What I would suggest is use the local scope and do something like the following.

As everyone said you need to scope your variables with var or local. Also as @Ben said, you can't really var scope variables like you have. What I would suggest is use the local scope and do something like the following: var val = 'some value' local = { var1 = duplicate(val), var2 = duplicate(val), var3 = duplicate(val) }; That, in my opinion, is the fastest way to achieve what you seem to be doing.

I use the duplicate function just so if you use a complex variable as the value of val (struct, array, etc) you don't run into issue with references.

Does not scope variables. To properly scope the variables requires the var keyword Otherwise the variables will be created, but assigned to the default scope. The default scope depends on the context and what version of CF we are talking about.

For CFC methods: CF9 -> LOCAL scope CF8 -> VARIABLES scope Because of the scoping rules in CF9 the var keyword is not really needed. Variables can be added to the LOCAL scope directly and at any time (There is no need scope them ahead of time.

I suppose I should start by pointing out that your code doesn't var scope the variables, it just sets their values. You need to use the VAR keyword (or LOCAL scope in CF9) to specify that the variables should be VAR scoped. Furthermore, chaining assignments doesn't work in all versions of CF.My workplace is still on 6.1, and this throws an error.

Finally, if I recall correctly, if you use the assignment statement as above, var1 and var2 are equal to true, as the result of an assignment operation is true if no error occurred. (someone correct me if I'm wrong, since I can't test it at work, since we're on 6.1) Anyway, to get back to your question, I don't chain assignment or scoping ever. First, I think individual assignments are clearer.

Second, it doesn't work in all versions. So I would suggest that individual assignments would be preferred.

I do not like chaining either, but a quick test with CF9 shows all variables equal to an empty string. However var2 and var3 are placed in the shared variables scope (not function local). – Leigh Apr 21 at 17:33.

I've seen people simply create a var struct and define your variables as keys for the struct. This way you don't have to use var all the time. E.g.

: This is helpful for those who use older versions of ColdFusion Server and are stuck with the var scope.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions