• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$query->row() returns array ALWAYS

If I do something like
$query = $this->db->get($this->table, $this->limit, $this->offset);        
return $query->row();
and that certain get() doesn't actually find a record (doesn't exist, for instance), row() returns an array.

I can't think of a time when I would ever want it return an array instead of an object just because it's empty.

Even if specify through row(0, 'object'), it still comes back as an empty array instead of an empty object. I've looked at DB_result.php and can't find where this is happening. Any help with this would be great. Maybe I'm missing something.


DB_result.php, line 72.

OK, I see. Am I wrong in thinking that it should be an empty stdClass?

No, the result_object() method should return an object, not an array. So this is a bug.

You could debate if either an array or object should be returned if you request something that doesn't exist.
I would prefer FALSE, to make it easier to test the result of a $query->row() call. Now it returns an array, and you have to test if it's empty to avoid errors about missing array elements (or in your case, getting an array back instead of an object).

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.