嘿那里,这是给你们的问题.
我有很多时间为PHP中的类选择错误处理.
对于Ajax PHP处理类中的示例,我这样做:
public function setError($msg) {
$this->errors[] = $msg;
}
public function isFailed() {
return (count($errors) > 0 ? true : false); // if errors > 0 the request is failed
}
public function getJsonResp() {
if($this->isFailed()) {
$resp = array('result' => false, 'message' => $this->errors[0]);
} else {
$resp = array('result' => true);
array_merge($resp, $this->success_data); // the success data is set later
}
return json_encode($resp);
}
// an example function for a execution of a method would …Run Code Online (Sandbox Code Playgroud)