Page 1 of 1
return object from a service
Posted: Tue Mar 22, 2005 3:45 pm
by andre_c
if a service is supposed to return a specific type of object if it finds its matching record on a table, what should it return if doesn't find a matching row?
null? false? empty object?
(maybe this should be on the theory forum)
Posted: Tue Mar 22, 2005 3:59 pm
by feyd
null or false, is what I tend to return.. depends on if an error occurs for others.
since you are talking about database records being found, I would return null, as that would tell me an empty result set. False would tell me an error.
Posted: Tue Mar 22, 2005 4:01 pm
by andre_c
null it is then,
thanks
Posted: Tue Mar 22, 2005 5:24 pm
by Pyrite
Posted: Wed Mar 23, 2005 1:30 am
by timvw
i prefer to return false... because the operation failed.
but then again, i would use a reference as parameter in which the object has to be returned
Code: Select all
function lookup(&$thingie)
{
// lookup object
$thingie =& something;
// object was found, thus return true
return true;
}
this way you can check if the operation succeeded... and then acces the found object, because $thingie will be a reference to it...
Posted: Wed Mar 23, 2005 11:02 am
by andre_c
hmm, using false makes me think that if it found the object it would return true. So in timvw's example, using false makes sense.
But i want the service to return an object, not a boolean, so using null seems to make more sense in this case to me now.