That's a little obscure. You're var scoping that variable by simply setting it to an empty string before you effectively reassign it as the query name in the cfquery tag. You could also do <cfset var coreLV = queryNew(columnlist [, columntypelist]) >, but it's easier to just let ColdFusion dynamically reassign it.

It's important particularly to var scope variables like this so they don't wind up in the variables scope of the CFC and possibly cause unintended consequences. Sometimes it doesn't make any difference, but when it does, it's very difficult to debug, because the problem is quite hidden. So it's better to make sure you always var scope local variables.

It's kinda similar to how you can affect a .cfm template where you have a local variable set on the page. Something like:

<cfset myName = "Joe" >

If someone messes with the query string in the url and adds &myName=Tommy to the end, myName changes, and that can mess things up.

If instead, you place myName in the request scope :

<cfset request.myName = "Joe" >

it can't be unintentionally affected by url or form scopes.

var scoping your local variables in your functions follows the same principle. It ensures the function is encapsulated so that any variable assignments that happen within it do not affect anything else (and perhaps visa versa).

Once you get into more heavy duty CFC use, serious problems can arise from neglecting this small detail.

:) Nando

Hamoud, Ryan N. wrote:
OK this all makes a little more sense......
1 question I have is why are you guys defining coreLV like this
<cfset var coreLV = "">
I am just trying to make sure I am on the same page with everyone.  coreLV is a constant that is set on another page before it enters my cfc
 


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]

Reply via email to