Brad-

Maybe its a bug and maybe its just a bad error message. I came across
this problem a while back when I had a student who was trying to
build a system where some files could sometimes be called as a custom
tag and sometimes as a plain template (about like you're doing).

The behavior feels wrong.  You've covered a lot of the same ground that
I did when I the student (I wish I could remember his name) pointed it
out.  I'll reconstruct my tests (much of which review/echo what you've
done):

--------
foo.cfm looks like this:

<cfset ATTRIBUTES.x=structnew()>


If you call foo.cfm as a custom tag it will run fine.
If you call foo.cfm directly it will throw the error you've already
noted in this thread.

--------
Change foo.cfm to:

<CFOUTPUT>#isStruct(ATTRIBUTES)#</cfoutput>

If you call foo.cfm as a custom tag it will return "YES".
If you call foo.cfm directly it will throw variable not defined error.

--------
Now let's change foo.cfm to:

<CFSET ATTRIBUTES=structnew()>
<cfset ATTRIBUTES.x=structnew()>

If you call foo.cfm as a custom tag it will run fine.
If you call foo.cfm directly it will run fine.


--------
Which leads us to the code-around for the problem:

<CFIF NOT IsDefined("ATTRIBUTES")>
        <CFSET ATTRIBUTES=StructNew()>
</cfif>
<cfset ATTRIBUTES.x=structnew()>

Which is uglier than it ought to be but does seem to work.


It seems to me (but I may be wrong) that the explanation is that
the ATTRIBUTES structure (scope) is automatically defined when a file
is called as a custom tag but is not automatically defined when a
file is called directly.  Because ATTRIBUTES is not defined it would
follow that you can not make one of its keys into a structure.  (A
conclusion you reached as well.) If that reasoning bears out this is
just a confusing error message.

To test our thinking make one more change to foo.cfm:

<CFIF NOT IsDefined("ATTRIBUTES")>
        <CFSET ATTRIBUTES=StructNew()>
</cfif>
<CFOUTPUT>#isStruct(ATTRIBUTES)#</cfoutput>

<cfset ATTRIBUTES.x=structnew()>
<CFSET cheese.y=Structnew()>

If our idea makes sense when we call the file as a custom tag we should
get the "Cannot assign result to symbol cheese.y" and ... we do.

So really (maybe) this is just a confusing error message.

And, BTW, all of this seem to hold true on CF5.0 as well.


The thing I haven't played with is the Array stuff.  I will now-
thanks for bringing it up.

Craig Fisher
Alta Interactive, Inc.
http://www.altainteractive.com/
[EMAIL PROTECTED]
801-791-8251


-----Original Message-----
From: Brad Roberts [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 24, 2001 3:45 PM
To: CF-Talk
Subject: Conclusion? (RE: Attributes Scoped Structure?)


Okay, I think I'm getting somewhere.

First, you can create an array in the attributes scope.  The following
works.
        ---------------------------------------------------------
        <cfset attributes.test=arraynew(2)>
        <cfoutput>#arraylen(attributes.test)#</cfoutput>
        ---------------------------------------------------------

I created a custom tag called <cf_test>:
        ---------------------------------------------------------
        <!--- test.cfm --->
        <cfoutput>
                #IsStruct(attributes)#
        </cfoutput>
        ---------------------------------------------------------
When calling the custom tag above <cf_test>, the result is "yes".
"Attributes" must be a default structure within a custom tag.


I then changed <cf_test> to this:
        ---------------------------------------------------------
        <!--- test.cfm --->
        <cfset attributes.temp=structnew()>
        <cfoutput>
                #IsStruct(attributes.temp)#
        </cfoutput>
        ---------------------------------------------------------
Again, the result was "yes".

So, why can you create an attributes scoped structure inside of a custom
tag, but not in your normal template?

I'm concluding that the attributes scope has to be a structure first, and
then you can nest a structure inside it.

The following works fine in a normal template:
        ---------------------------------------------------------
        <cfset attributes=structnew()>
        <cfset attributes.test=structnew()>
        <cfoutput>#isstruct(attributes.test)#</cfoutput>
        ---------------------------------------------------------

Is this a bug?  Anyone else have an opinion?

Brad


> -----Original Message-----
> From: Howarth, Craig (IBK-NY) [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, May 24, 2001 2:20 PM
> To: CF-Talk
> Subject: RE: Attributes Scoped Structure?
>
>
> This is interesting and I don't have an answer.  Perhaps someone
> else can explain this.
>
> The statement
>
> <cfset attributes.temp=structNew()>
>
> will fail as described below if placed in a standard template,
> but works fine in a custom tag.  This led to my response to Brad.
>  Not being a Fuseboxer, I should have experimented further.
>
> As Jason points out the following works fine in a standard template:
>
> <cfset attributes.temp=3>
>
> Why the difference with assigning simple values to attributes
> scope as opposed to structures?
>
> > -----Original Message-----
> > From:       Jason Lotz [SMTP:[EMAIL PROTECTED]]
> > Sent:       Thursday, May 24, 2001 11:58 AM
> > To: CF-Talk
> > Subject:    Re: Attributes Scoped Structure?
> >
> > That's not true.  Fusebox uses nothing but Attributes scoped
> variables.  You
> > can set Attributes variables anywhere.
> >
> > ----- Original Message -----
> > From: "Howarth, Craig (IBK-NY)" <[EMAIL PROTECTED]>
> > To: "CF-Talk" <[EMAIL PROTECTED]>
> > Sent: Thursday, May 24, 2001 7:36 AM
> > Subject: RE: Attributes Scoped Structure?
> >
> >
> > Brad,
> >
> > The attributes scope can only be used within a custom tag.  This is the
> > error message that you get when you attempt to assign a value to the
> > attributes scope in a normal template.
> >
> > Craig
> >
> > > -----Original Message-----
> > > From: Brad Roberts [SMTP:[EMAIL PROTECTED]]
> > > Sent: Thursday, May 24, 2001 9:55 AM
> > > To: CF-Talk
> > > Subject: Attributes Scoped Structure?
> > >
> > > Can you set a structure in the attributes scope?
> > >
> > > I'm wondering why this isn't working:
> > >
> > > <cfset attributes.temp=structnew()>
> > >
> > > I get the following error:
> > > Cannot assign result to symbol attributes.temp
> > >
> > > Thanks in advance,
> > >
> > > Brad
> > >
> > >
> >
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to