我按照老师方法
class ExceptionHandler extends Handle{
private $code;
private $msg;
private $errorCode;
//需要返回客户端当前请求的URL路径
public function render(\Exception $e){
dump($e);
if($e instanceof BaseException){
//如果是自定义的异常
$this->code = $e->code;
$this->msg = $e->msg;
$this->errorCode = $e->errorCode;
}else{
//系统异常
$this->code = 500;
$this->msg = '系统内部错误';
$this->errorCode = 999;
}
$request = Request::instance();
$result = [
'msg' => $this->msg,
'error_code' => $this->errorCode,
'request_url'=> $request->url()
];
return json($result, $code);
}
}
打印出来 是下面的情况 是什么问题???
object(think\exception\ErrorException)#12 (9) {
["severity":protected] => int(64)
["data":protected] => array(0) {
}
["message":protected] => string(112) "Access level to app\lib\exception\BaseException::$code must be protected (as in class think\Exception) or weaker"
["string":"Exception":private] => string(0) ""
["code":protected] => int(0)
["file":protected] => string(69) "/www/web/disc/public_html/application/lib/exception/BaseException.php"
["line":protected] => int(12)
["trace":"Exception":private] => array(1) {
[0] => array(4) {
["function"] => string(11) "appShutdown"
["class"] => string(11) "think\Error"
["type"] => string(2) "::"
["args"] => array(0) {
}
}
}
["previous":"Exception":private] => NULL
}