[eluser]Colin Williams[/eluser]
You should employ the rule of a single exit point:
Code:
function getStuff($id=false)
{
$result = array();
if ($id)
{
$result = $this->db->get_where( 'stuff', array('id' => $id) );
}
return $result;
}
Then you can come in later and put what you need in $result before the conditional. My hunch is that the reason your want an "empty" db object is because you want to avoid errors where your controller tries to use $result->row(), etc. Just don't be lazy and run an isset() check first. Actually, I wouldn't even return db objects ever.
You could also just run the query.. if id is FALSE, you'll get an empty result. (No sense in running a dummy query as previously suggested)
Code:
function getStuff($id=false)
{
return $this->db->get_where( 'stuff', array('id' => $id) );;
}