Friday, December 4, 2009

Typed Arrays in ColdFusion...kind of.

You read it right but I'll warn you now it'll make you feel a little icky.If you are storing a composite relationship via a private array you've probably been using the type of "array" all these years. You can pseudo type your array in CF9 and I even think you could do this all the way back in  6.1 but back then an empty array would throw an error. Anyway,if you choose to do so you can pseudo-type your arrays in this fashion:




Back in 6.1 if that array was empty, it would throw an exception but that doesn't seem to happen anymore.  Simple use the type and add the array notation (open-close brackets) and viola it works. I kinda have a type safe array... kind of. It only checks the type of the FIRST element in the array. So I could have an Address object in the first position and an int in the next and it will NOT fail.


Half kudos, half fail.


PEACE.

1 comment:

Unknown said...

Must use the type="array" if you are defining a one-to-many relationship in cf-orm in CF9 though.

What's with this textarea? Home/End/Arrow keys/copy & paste don't work!!!! *frustrating*