Default variable scope
The default scope for variables you use in functions is global. If you want a local variable, you have to declare it at the beginning of your function.
I realised this when I added logging to the end of one of my functions, and discovered that the variables that I was logging had changed value by the logging code. I now understand that this is to be expected with recursive methods.
I don't object to having to declare all my variables as this is a good habit (though hard without decent tool support, is there something as nice as Idea for Coldfusion?).
It seems that these coldfusion UDF tips are a good read, tip 3 tells you to Var your variables to make them local. What sort of madman made them global by default. Ick ick ick.
I realised this when I added logging to the end of one of my functions, and discovered that the variables that I was logging had changed value by the logging code. I now understand that this is to be expected with recursive methods.
I don't object to having to declare all my variables as this is a good habit (though hard without decent tool support, is there something as nice as Idea for Coldfusion?).
It seems that these coldfusion UDF tips are a good read, tip 3 tells you to Var your variables to make them local. What sort of madman made them global by default. Ick ick ick.
0 Comments:
Post a Comment
<< Home