## 调试 由于 MixPHP 是在命令行中启动的,所以使用 `echo`、`var_dump`、`print_r` 调试时,输出结果并不在浏览器中,而是在执行命令的终端里。 ## HTTP 404 / 500 框架默认代码只拆分了 400/500 两种 HTTP 错误,如需定制: [>> 修改 StartCommand.php#L135 源码 <<](https://github.com/mix-php/mix-skeleton/blob/master/app/Http/Commands/StartCommand.php#L135) - 修改为 json 格式: ~~~ /** * 404处理 * @param \Throwable $e * @param Response $response * @throws \PhpDocReader\AnnotationException * @throws \ReflectionException */ public static function show404(\Throwable $e, Response $response) { $json = JsonHelper::encode([ 'message' => $e->getMessage(), 'type' => get_class($e), 'code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTraceAsString(), ], JSON_UNESCAPED_UNICODE); $response->withBody((new StreamFactory())->createStream($json)) ->withStatus(404) ->withContentType('application/json', 'utf-8') ->end(); } /** * 500处理 * @param \Throwable $e * @param Response $response * @throws \PhpDocReader\AnnotationException * @throws \ReflectionException */ public static function show500(\Throwable $e, Response $response) { $json = JsonHelper::encode([ 'message' => $e->getMessage(), 'type' => get_class($e), 'code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTraceAsString(), ], JSON_UNESCAPED_UNICODE); $response->withBody((new StreamFactory())->createStream($json)) ->withStatus(500) ->withContentType('application/json', 'utf-8') ->end(); } ~~~