Maybe we could convince MM to add an attribute to CFINCLUDE like
"LOCALIZEVARIABLES={true,false}" to control this behavior. This has really
thrown us for a loop here, considering we're retrofitting some old
cfmodule/cfinclude based code.
:(
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Nathan Dintenfass
Sent: Friday, May 07, 2004 2:54 PM
To: [EMAIL PROTECTED]
Subject: RE: [CFCDev] CFINCLUDE forces var scope into arguments?
I can verify it. In fact, I am very disappointed that this is the way MACR
chose to implement this.
In theory, since a 'var' value takes precedence over VARIABLES, as long as
you always use "var" you should be 'safe' for cross-method calls. The
classic example being a method that loops over "var i" and inside the loop
calls another method that loops over "var i" -- even if you CFINCLUDE inside
that method you should still be OK, but this behavior could result in really
subtle bugs if, for instance, you have a typo in a 'var' variable in one
method.
Ultimate impact: yet another reason to ALWAYS ALWAYS ALWAYS use "var" to
define local variables.
Here's a really simple example:
-----cfc.cfc-------
<cfcomponent>
<cffunction name="foo">
<Cfset var hello = "I am hello">
<cfdump var="#variables#">
<cfinclude template="include.cfm">
<cfreturn "foo was called">
</cffunction>
<cffunction name="get">
<cfdump var="#variables#">
</cffunction>
</cfcomponent>
-----test.cfm-----
<cfscript>
foo = createObject("component","cfc");
foo.foo();
foo.get();
</cfscript>
[put anything in include.cfm]
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Jim Davis
> Sent: Friday, May 07, 2004 11:31 AM
> To: [EMAIL PROTECTED]
> Subject: RE: [CFCDev] CFINCLUDE forces var scope into arguments?
>
>
> True... has this aspect been verified, tho?
>
> In other words do the variables set actually overwrite variables in other
> requests on the same instance? Are the local-now-variable values
> available
> after the include finishes processing?
>
> I guess this is something I'll have to experiment with and possibly change
> my whole design...
>
> Jim Davis
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> > Of Barney Boisvert
> > Sent: Friday, May 07, 2004 12:24 PM
> > To: [EMAIL PROTECTED]
> > Subject: RE: [CFCDev] CFINCLUDE forces var scope into arguments?
> >
> > That won't get around it, because when you CFINCLUDE, the 'local' struct
> > will dump to 'variables', which means one copy of 'local' for the CFC
> > _instance_. As soon as you get two concurrent method calls, you'll have
> > issues. If you pick a unique name within the CFC (for
> instance, the name
> > of
> > the function), then it'll work.
> >
> > Cheers,
> > barneyb
> >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED]
> > > [mailto:[EMAIL PROTECTED] On Behalf Of Jim Davis
> > > Sent: Friday, May 07, 2004 8:57 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: RE: [CFCDev] CFINCLUDE forces var scope into arguments?
> > >
> > > For exactly this reason (well... and a coupla others) I
> > > create a pseudo
> > > scope for all function local variables.
> > >
> > > I add the following line to the top of every function (after
> > > the args):
> > >
> > > <cfset var local = StructNew()>
> > >
> > > Then use only key in "local" for all function-local
> > > variables. It doesn't
> > > prevent the glitch, but as long as you never use "local" as a
> > > var name other
> > > than that it does greatly minimize the impact of it.
> > >
> > > Jim Davis
> > >
> > > > -----Original Message-----
> > > > From: [EMAIL PROTECTED]
> > > [mailto:[EMAIL PROTECTED] On Behalf
> > > > Of Roland Collins
> > > > Sent: Thursday, May 06, 2004 6:05 PM
> > > > To: [EMAIL PROTECTED]
> > > > Subject: RE: [CFCDev] CFINCLUDE forces var scope into arguments?
> > > >
> > > > Not a fan of this glitch. It renders var pretty useless in
> > > any function
> > > > using a cfinclude then. :(
> > > >
> > > > -----Original Message-----
> > > > From: [EMAIL PROTECTED]
> > > [mailto:[EMAIL PROTECTED] On Behalf
> > > > Of Barney Boisvert
> > > > Sent: Thursday, May 06, 2004 6:01 PM
> > > > To: [EMAIL PROTECTED]
> > > > Subject: RE: [CFCDev] CFINCLUDE forces var scope into arguments?
> > > >
> > > > That's so that you can use CFINCLUDE inside functions and
> > > you'll be able
> > > > to
> > > > access variables. This is a little tiny "glitch" that was
> > > allowed through
> > > > so you can reap greater benefits (being able to use
> > > CFINCLUDE in functions
> > > > at all).
> > > >
> > > > Basic templates don't know about the local scope, because
> > > its only for
> > > > functions/methods. In other words, in order for the template you're
> > > > CFINCLUDEing into your function to be able to access the
> > > local variables
> > > > (including arguments), they have to be moved to a scope the
> > > template can
> > > > access them in.
> > > >
> > > > Cheers,
> > > > barneyb
> > > >
> > > > > -----Original Message-----
> > > > > From: [EMAIL PROTECTED]
> > > > > [mailto:[EMAIL PROTECTED] On Behalf Of Roland Collins
> > > > > Sent: Thursday, May 06, 2004 2:54 PM
> > > > > To: [EMAIL PROTECTED]
> > > > > Subject: [CFCDev] CFINCLUDE forces var scope into arguments?
> > > > >
> > > > > I just noticed an odd behavior that I wanted to confirm.
> > > > >
> > > > > I have a CFC that has a function that uses a CFINCLUDE in the
> > > > > function to
> > > > > set some variables. At the top of that function, I have a
> > > > > bunch of "var"
> > > > > scoped variables. If I dump the "variables" scope
> > > immediately after
> > > > > declaring these, all is well - they don't show up. After
> > > I call the
> > > > > CFINCLUDE however, if I dump the "variables" scope, all of my
> > > > > "var" scope
> > > > > variables have been dumped into the "variables" scope!!!!!
> > > > >
> > > > > I though I was crazy at first, but I've tried it numerous
> > > > > times now, and
> > > > > it's always true! Attached is a simple test case. Run
> > > > > test.cfm and you'll
> > > > > see what I mean.
> > > > >
> > > > > !?!?!?!
> > > > >
> > > > > Roland
> > > > >
> > > >
> > > > ----------------------------------------------------------
> > > > You are subscribed to cfcdev. To unsubscribe, send an email
> > > > to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> > > > in the message of the email.
> > > >
> > > > CFCDev is run by CFCZone (www.cfczone.org) and supported
> > > > by Mindtool, Corporation (www.mindtool.com).
> > > >
> > > > An archive of the CFCDev list is available at
> > > > www.mail-archive.com/[EMAIL PROTECTED]
> > > >
> > > >
> > > > ----------------------------------------------------------
> > > > You are subscribed to cfcdev. To unsubscribe, send an email
> > > > to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> > > > in the message of the email.
> > > >
> > > > CFCDev is run by CFCZone (www.cfczone.org) and supported
> > > > by Mindtool, Corporation (www.mindtool.com).
> > > >
> > > > An archive of the CFCDev list is available at www.mail-
> > > > archive.com/[EMAIL PROTECTED]
> > >
> > >
> > >
> > > ----------------------------------------------------------
> > > You are subscribed to cfcdev. To unsubscribe, send an email
> > > to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> > > in the message of the email.
> > >
> > > CFCDev is run by CFCZone (www.cfczone.org) and supported
> > > by Mindtool, Corporation (www.mindtool.com).
> > >
> > > An archive of the CFCDev list is available at
> > > www.mail-archive.com/[EMAIL PROTECTED]
> > >
> >
> > ----------------------------------------------------------
> > You are subscribed to cfcdev. To unsubscribe, send an email
> > to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> > in the message of the email.
> >
> > CFCDev is run by CFCZone (www.cfczone.org) and supported
> > by Mindtool, Corporation (www.mindtool.com).
> >
> > An archive of the CFCDev list is available at www.mail-
> > archive.com/[EMAIL PROTECTED]
>
>
>
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email
> to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
> in the message of the email.
>
> CFCDev is run by CFCZone (www.cfczone.org) and supported
> by Mindtool, Corporation (www.mindtool.com).
>
> An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at
www.mail-archive.com/[EMAIL PROTECTED]
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).
An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]