RE: [PHP] php programming style
| From: | Beau Hartshorne | Date: | Thu, 21 Nov 2002 18:54:50 +0000 |
| Subject: | RE: [PHP] php programming style | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125463@lists.php.net to get a copy of this message | ||
> I think that some of the above question might help you out. However,
> from a programming standpoint i like to make sure that my functions
> return the same type at least. Some feel different about this and
> return various type (ie, int, strings, arrays)...
I agree that it should return a consistent type. I was planning on
returning a populated array on success, or a boolean false on fail.
Instead, I will return an empty (but initialized) array on fail, and use
the count() function to test for failure like this:
<?php
function foo()
{
/* if the result set is empty */
return array();
}
$my_array = foo();
if (count($my_array) <= 0) {
// nothing in array
echo 'nothing';
} else {
// do something with data
echo 'something';
}
?>
Beau