Welcome Guest, Not a member yet? Register   Sign In
$query->row() returns array ALWAYS
#1

[eluser]kmanlove[/eluser]
If I do something like
Code:
$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.

Thanks,
Keith
#2

[eluser]WanWizard[/eluser]
DB_result.php, line 72.
#3

[eluser]kmanlove[/eluser]
OK, I see. Am I wrong in thinking that it should be an empty stdClass?
#4

[eluser]WanWizard[/eluser]
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).




Theme © iAndrew 2016 - Forum software by © MyBB