![]() |
What is better when return false - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: What is better when return false (/showthread.php?tid=68365) |
What is better when return false - wolfgang1983 - 06-29-2017 Hello when using return false I would also like to know if return "" is OK Or which one is better over the other. PHP Code: public function getattachments($where_column = '', $id = '') RE: What is better when return false - Paradinight - 06-29-2017 (06-29-2017, 07:42 PM)wolfgang1983 Wrote: Hello when using return false I would also like to know if return "" is OK Return an empty array. RE: What is better when return false - wolfgang1983 - 06-29-2017 (06-29-2017, 08:15 PM)Paradinight Wrote:(06-29-2017, 07:42 PM)wolfgang1983 Wrote: Hello when using return false I would also like to know if return "" is OK Something like return array(); RE: What is better when return false - Paradinight - 06-29-2017 (06-29-2017, 09:17 PM)wolfgang1983 Wrote:(06-29-2017, 08:15 PM)Paradinight Wrote:(06-29-2017, 07:42 PM)wolfgang1983 Wrote: Hello when using return false I would also like to know if return "" is OK yes or PHP Code: return $query->result_array(); without $query->num_rows() ![]() RE: What is better when return false - rtenny - 06-30-2017 Yes that's what I do as well if the success case would return an array then i would return an empty array if success would return a string then an empty return string That way the return value is consistent RE: What is better when return false - SomeGuy - 04-06-2018 Hope you decided to return NULL. Returning an empty array when there are no results is not the same as returning an array with known keys. You'll have to validate the array before you can actually use it. PHP Code: if(NULL !== ($attachments = $model->getAttachments())) : RE: What is better when return false - InsiteFX - 04-06-2018 PHP Code: if (!empty($array)) empty is great for arrays, but very bad for using on strings "0". |