Should I convert data arrays to objects in PHP in a CouchDB/Ajax app?
Posted
by karlthorwald
on Stack Overflow
See other posts from Stack Overflow
or by karlthorwald
Published on 2010-05-27T17:34:19Z
Indexed on
2010/05/27
17:51 UTC
Read the original article
Hit count: 154
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?
© Stack Overflow or respective owner