Coldfusion and unscoped variables -
I am currently checking all my functions and components for unscoped variables. I am using a device called to look at all the works, looking at the following code, the WordScript tells me that the "Input" variable on the line 4 in the Unsocked. Is this true and do I need to scope the argument variables if I change it? FYI does not report any unassipped variables, if I do not change logic variables in function varscoper4. You can also see for yourself what it looks like to dump the various scops and see the output. I strongly encourage you to take the output of your webshop tool, where you should clearly have the scope of your variable. In that case, your first block of code will look like this, for clarity and certainty in your code. Personally, I do not like to set and change logic in my functions and methods. I want to keep them unnecessarily as it is in the second block of your code. But even so, I will clearly cover the arguments, so that you know where it came from - even if it has not been flagged by the wizard. If this is not clear then the last thing to be added here is that work scoping connects everything to the local area. You can also do this and it will be done in the previous block of functional code. Equals: & lt; Cfoutput & gt; #testit (1) # & lt; / Cfoutput & gt; & Lt; Cffunction name = "testit" & gt; & Lt; Cfargument name = "input" & gt; & Lt; CFSet input = 3 & gt; & Lt; Cfreturn input & gt; & Lt; / Cffunction & gt;
& lt; Cfoutput & gt; #testit (1) # & lt; / Cfoutput & gt; & Lt; Cffunction name = "testit" & gt; & Lt; Cfargument name = "input" & gt; & Lt; Cfset var output = 3 + input & gt; & Lt; Cfreturn output & gt; & Lt; / Cffunction & gt; In your fist code block, the input is "unsigned", but CF interprets it as argument. Scope The CF will always try to find its unsold variable through a priority order. You can find more information here:
& lt; Cfoutput & gt; #testit (1) # & lt; / Cfoutput & gt; & Lt; Cffunction name = "testit" & gt; & Lt; Cfargument name = "input" & gt; & Lt; Cfset input = 3 & gt; & Lt; Cfdump var = "# variables #" label = "variables" & gt; & Lt; Cfdump var = "# logic #" label = "argument" & gt; & Lt; Cfdump var = "# local #" label = "local" & gt; & Lt; Cfreturn input & gt; & Lt; / Cffunction & gt;
& lt; Cfoutput & gt; #testit (1) # & lt; / Cfoutput & gt; & Lt; Cffunction name = "testit" & gt; & Lt; Cfargument name = "input" & gt; & Lt; Cfset arguments.input = 3 & gt; & Lt; Cfdump var = "# variables #" label = "variables" & gt; & Lt; Cfdump var = "# logic #" label = "argument" & gt; & Lt; Cfdump var = "# local #" label = "local" & gt; & Lt; Cfreturn arguments.input & gt; & Lt; / Cffunction & gt;
Comments
Post a Comment