Should I convert data arrays to objects in PHP in a CouchDB/Ajax app?
- by karlthorwald
I find myself converting between array and object all the time in PHP application that uses couchDB and Ajax. Of course I am also converting objects to JSON and back (for sometimes couchdb but mostly Ajax), but this is not so much disturbing my workflow.
At the present I have php objects that are returned by the CouchDB modules I use and on the other hand I have the old habbit to return arrays like array("error"="not found","data"=$dataObj) from my functions. This leads to a mixed occurence of real php objects and nested arrays and I cast with (object) or (array) if necessary. The worst thing is that I know more or less by heart what a function returns, but not what type (array or object), so I often run into type errors.
My plan is now to always cast arrays to objects before returning from a function. Of course this implies a lot of refactoring.
Is this the right way to go? What about the conversion overhead? Other ideas or tips?