Reputation: 309
In CakePHP 3 a find
returns an object instead of an array. I know that you can convert the object into an array using toArray()
. I'm trying to decide which is "better" to use. I know this can be seen as a subjective question, but I don't mind, I'm interested in your answers.
I read about object vs array, but can't really get a good answer out of what I googled and read. Person X says that using objects is better or faster, Person Y says using arrays is. So I thought I would ask here.
So while keeping CakePHP in mind, does it matter if you use the returned object or convert it into an array performance wise?
Upvotes: 1
Views: 3737
Reputation: 411
Performance wise, it depends. If you disable hydration as in https://book.cakephp.org/3.0/en/orm/query-builder.html#getting-arrays-instead-of-entities
Then any performance hit is negligible. However, if you perform the query then call toArray on the entities, that's a bit slower performance wise.
As far as which is better, that's largely dependent on your particular use-case. There are some cases where it's better to have an array, and some where the object may be preferred. Without context, which is better is unanswerable.
Upvotes: 3