小编000*_*000的帖子

PHP类中的错误处理

嘿那里,这是给你们的问题.

我有很多时间为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)

php error-handling class

2
推荐指数
2
解决办法
1万
查看次数

标签 统计

class ×1

error-handling ×1

php ×1