Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.1 版本 Request->only 空值被忽略问题 #2991

Open
wants to merge 2 commits into
base: 5.1
Choose a base branch
from

Conversation

suanju
Copy link

@suanju suanju commented Mar 20, 2024

老项目中遇到的一个问题发现在6.x版本中被修复 具体pr

当请求类型为POST,传递类型为json时,以curl为例:

curl --location --request POST 'http://test.cn/' \
--header 'Content-Type: application/json' \
--header 'Content-Length: 14' \
--data-raw '{"name": null}'

控制器使用如下代码时

<?php
namespace app\index\controller;
use think\Request;

class Index
{
    public function index(Request $request)
    {
        var_dump($request->param());
        var_dump($request->only(['name']));
    }

返回的结果为

array(1) {
  ["name"]=> null
}
array(0) {
}

使用key_exists替换isset key_exists php 4.0.6 开始支持

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants