Some previous answers here for background reading
我有一个看起来像这样的函数:
function do_something_to_db($db_object, $param1, $param2){
if (!isset($param1) || !isset($param2)){
// Let user know that user-supplied arguments are incorrect.
} else {
$db_object->do_some_call($param1, $param2);
if ($db_object->is_last_call_success()){
$valuable_number = $db_object->get_last_call_result();
// Success: let user know information from database call.
} else {
// Let user know that database call failed.
}
}
}
因此,对于这三种情况中的每一种情况,我都需要沟通:
使用返回码和常量或使用例外来表达它是否更清楚?还是有一些替代方案会更好?请关注答案中的可读性和可维护性!