When is an array not an array
Coldfusion 9.0.1 added for-in looping over arrays, which is great, it's much simpler and a lot less verbose than having to iterate over with an index.
<cfscript>
for(item in myarray) {
doSomething(item);
}
</cfscript>
While writing a little bit of code to loop over properties in a Coldfusion ORM cfc, naturally i used the for-in syntax. Here's the basics of what i wanted to do;
<cfscript>
public void function postLoad( any entity ) {
var md = getMetaData(this);
for(var p in md.properties) {
doSomething(p);
}
}
</cfscript>
But CF wasn't having any of it and threw me an error.
coldfusion.runtime.ScopeCastException: You have attempted to dereference a scalar variable of type class [Ljava.lang.Object; as a structure with members.

As you can see the md.properties key definetely looks like an array when you cfdump it, however its java type is not a coldfusion.runtime.Array, its a java.lang.Object[] and while cfdump is happy to make it look like an array, it seems that this is incompatible with the for-in array syntax
Its a shame to find little inconsistencies like this, whilst it doesn't impact on the functionality because you can easily work around by using index based looping, its just another quirk to remember and i've only got limited space to remember these things!
There is a bug report filed on cfbugs for this issue
Comments
for(var p in md.properties){};
[url=http://www.facebook.com/pages/Betathome-new-promotions/263682786990966]betathome[/url]