What do you return when a function fails?
Posted: Tue Nov 08, 2005 7:11 pm
Let's say you have a function to retrieve member id of the user from the user name.
Suppose you do find the user name invalid and you are not able to return the member id, do you return FALSE, 0 or appropriate error messages.
I used to return FALSE so far, but when I tried to echo the returned FALSE, I don't get anything it returns empty string not FALSE.
example scenario
1. If return TRUE actually returns 1, when is it possible to use "call_me(10) === TRUE",,,this kind of statement?
2. Do you feel the behaviors desirable??? Advise me the best coding practices....Thanks
Suppose you do find the user name invalid and you are not able to return the member id, do you return FALSE, 0 or appropriate error messages.
I used to return FALSE so far, but when I tried to echo the returned FALSE, I don't get anything it returns empty string not FALSE.
example scenario
Code: Select all
echo call_me(3); //This echo call returns no value,,,the return value is EMPTY instead of FALSE
echo call_me(10);//This returns 1 instead of TRUE,,,is this desirable as well...
function call_me($number){
if ($number == 10) return TRUE;
else return FALSE
}2. Do you feel the behaviors desirable??? Advise me the best coding practices....Thanks