You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP开发Swagger登录认证报错:Cannot access offset of type string on string (0)

PHP登录认证Swagger测试报错:Cannot access offset of type string on string (0)

Cannot access offset of type string on string (0)

我正在用PHP开发Web应用,实现登录认证功能时,通过Swagger测试出现上述报错。已排查服务层和数据访问层的所有方法,仍未解决,使用var_dump()调试时同样触发该错误。

以下是路由代码:

/**
 * @OA\Post(
 *      path="/auth/login",
 *      tags={"auth"},
 *      summary="Login to system using email and password",
 *      @OA\Response(
 *           response=200,
 *           description="User data and JWT"
 *      ),
 *      @OA\RequestBody(
 *          description="Credentials",
 *          @OA\JsonContent(
 *              required={"email","pwd"},
 *              @OA\Property(property="email", type="string", example="example@example.com", description="User email address"),
 *              @OA\Property(property="pwd", type="string", example="some_password", description="User password")
 *          )
 *      )
 * )
 */
Flight::route('POST /login', function() {
    $payload = Flight::request()->data->getData();
    var_dump($payload);

    $user = Flight::get('auth_service')->get_user_by_email($payload['email']);
    var_dump($user);

    if(!$user || !password_verify($payload['pwd'], $user['pwd']))
        Flight::halt(500, "Invalid username or password");

    unset($user['pwd']);
});

内容的提问来源于stack exchange,提问作者Amir Bašović

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 20:42:38