ColdFusion Struct References
You need to be careful with references to objects or structs. I was looking at some old code the other day and I noticed I hadn't var'ed some local variables - very naughty of me. So I fixed the code but it no longer worked.
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
[Add Comment] [Subscribe to Comments]
I normally var the i for the loops as well (well, useually I just create a "local" struct and have all the variables in the function contained within that struct. It's nothing I've ever had a problem with, but I imagine it would lead to pretty sticky situations in figuring out what's going on.
# Posted By Sammy Larbi | 6/3/07 2:15 AM
Yes the i should be var'ed as well (it was in my code but that wasn't cause the issue so I left it out in the code above). I can't think of a situation that it would cause an issue, it's better to be safe than sorry.
# Posted By Justin Mclean | 6/3/07 11:09 AM
I guess if the class was a singleton and you had i as an iterator in 2+ methods it might be a problem, but for transients, I would assume the loop always gets completed and i is reset when complete (and generally, "i" wouldn't be used for anything else).
# Posted By Sammy Larbi | 6/4/07 2:25 AM