从函数返回错误给用户的标准方法是什么? (exeeded电子邮件无效,最大字符等)从函数中向用户返回错误的标准方法是什么?
function register($name, $email) {
if(!$name) {
$registration_errors = 'name empty,';
}
if(!email) {
$registration_errors = $errors . 'email empty,';
}
if($registration_errors) {
return $registration_errors;
}
else {
register stuff........
return true;
}
}
现在的问题是这样,你不能这样做,它总是返回true:
if(register()) {blah blah blah} else { put errors under inputs}
那么这将是这样做的标准方法这个?
这听起来不错。将验证放在函数之外是否更好?因为如果我曾经创建过移动版本,或者从另一个地方调用函数进行验证,看起来更容易 – user583951 2011-01-22 01:13:00