>> 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" />

That's exactly what I would expect. You're declaring a simple value or
string and then saying "I want to set a sub-element of this string to 'foo'"
-- but simple values don't have sub-elements, which is why it throws the
error, rather than assuming that you want to replace the existing variable
with a new structure.

Personally, I think that CF should require explicite declaration of
structures with StructNew() or something else, rather than assuming the new
structure, but that's just me.

>> 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" />

This is because you're explicitely replacing a structure (which contains the
sub-element) with a simple value ( "foo" ).

S. Isaac Dealey
Certified Advanced ColdFusion 5 Developer

www.turnkey.to
954-776-0046
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm

Reply via email to