framework
framework copied to clipboard
Request->post方法过滤器为a,空值会返回非空数组
vendor\topthink\framework\src\think\Request.php:979 function post()... 当前端config字段传空值,后端使用以下代码时, $postConfig = $this->request->post('config/a', []); $postConfig预期得到空值,但实际得到并非为空数组,而是有一个值为空字符串的数组,[""]。 而这个值在if ($postConfig) 会返回false.
6.0.8版本 vendor\topthink\framework\src\think\Request.php:1321行改为 $data = array_filter((array) $data); 后,问题解决。 代码块如下: /** * 强制类型转换 * @access public * @param mixed $data * @param string $type * @return mixed */ private function typeCast(&$data, string $type) { switch (strtolower($type)) { // 数组 case 'a': $data = array_filter((array) $data); break;
结果符合预期