framework
framework copied to clipboard
5.1 版本 Request->only 空值被忽略问题
老项目中遇到的一个问题发现在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 开始支持