That was my understanding as well. But what I was attempting to
demonstrate was that CF is able to auto-retype certain variables and not
others.

<!--- auto-create a struct --->
<cfset myStruct.foo = "bar" />

<!--- have cf retype to string --->
<cfset myStruct = "foo" />

That works fine.

<!--- create a string --->
<cfset myString = "foo" />

<!-- have cf retype to struct --->
<cfset myString.1 = "foo" />

That fails.

chris kief


-----Original Message-----
From: Sean A Corfield [mailto:sean@;corfield.org] 
Sent: Friday, November 01, 2002 11:02 AM
To: CF-Talk
Subject: Re: *CFMX* variable creation - is this normal behavior? or a
bug?

My understanding is that it's intentional - and a documented change  
from CF5. CFMX now automatically creates (and types) your variable  
based on first usage - previously myStruct.1 would be a single variable

name containing a '.' whereas in CFMX that auto-creates myStruct and  
then assigns a value to the key "1".

On Friday, Nov 1, 2002, at 10:21 US/Pacific, Chris Kief wrote:

> When creating an array or structure, CF allows things like this:
>
> <cfset myArray[1] = "foo" />
> <cfset myStruct.1 = "foo" />
>
> But if the variable has been previously set to a different data type
> (string in this case) like so:
>
> <cfset myArray = "foo" />
> <cfset myStruct = "foo" />
>
> <cfset myArray[1] = "foo" />
> <cfset myStruct.1 = "foo" />
>
> the following error is received:
>
> You have attempted to dereference a scalar variable of type class
> java.lang.String as a structure with members.
>
>
> You must specifically declare the variable as the new data type to
> prevent errors:
>
> <cfset myArray = "foo" />
> <cfset myStruct = "foo" />
>
> <cfset myArray = arrayNew(1) />
> <cfset myStruct = structNew() />
>
> <cfset myArray[1] = "foo" />
> <cfset myStruct.1 = "foo" />
>
> Was this a problem in CF5? Is this an expected behavior or a bug in
> CFMX? It should be mentioned that going the opposite direction works
> just fine:
>
> <cfset myArray[1] = "foo" />
> <cfset myStruct.1 = "foo" />
>
> <cfset myArray = "foo" />
> <cfset myStruct = "foo" />
>
> Your thoughts...
>
> chris kief
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Get the mailserver that powers this list at http://www.coolfusion.com

Reply via email to