« June 2006 | Main | August 2006 »

Array oddity in AMFPHP /Flex 2

Not sure if you want to file this under oddity or stupidity as I might e doing something completely wrong, but either way I discovered some unexpected behaviour.

I've been building a calendar application in Flex for creating,saving,duplicating and deleting events. The backend is php/mysql and I am using amfphp by extending the NetConnection as described in Jesse's post.

All works well but I noticed some weird behaviour when passing an array of items to a php service. Basically the service does a loop through the array an inserts for each item in the array. No biggie, just a standard foreach ($item as $key => $value) type of thing.

However something kept getting oddly screwed up and when I looked in the db, it seemed like an extra value was being entered. I couldn't figure out where this extra value was coming from, because prior to the call to the service, the data was valid.

Thank god for service capture. If you don't own that piece of software, you should. I fired it up and saw that the values being passed to the service included the length of the array along with the values the array contained.

I went back to the service in Flash 8 and tried the same call with the same data. The length value was never passed- so there is something odd going on. I thought about maybe forcing to hide the property on the array, even tho it is most obviously hidden in for loops, but forcing to hide it before sending it might work, but no luck. I did learn the property for hiding properties from the mercy of for loops - setPropertyIsEnumerable method on the Object class.

Anyways something is going on between the two versions - maybe its the way amfphp is used with Flex2.

Ideas? I wrote some server side stuff to handle it, but I'm interested in why this is happening.

Posted by bitch at 11:50 AM | Comments (5)