think-orm
think-orm copied to clipboard
save方法判断更新的数据时判断的问题
图中代码在php中结果为11,此处
/**
* 获取变化的数据 并排除只读数据
* @access public
* @return array
*/
public function getChangedData(): array
{
$data = $this->force ? $this->data : array_udiff_assoc($this->data, $this->origin, function ($a, $b) {
if ((empty($a) || empty($b)) && $a !== $b) {
return 1;
}
// ===========================此处=====================
return is_object($a) || $a != $b ? 1 : 0;
});
// 只读字段不允许更新
foreach ($this->readonly as $key => $field) {
if (array_key_exists($field, $data)) {
unset($data[$field]);
}
}
return $data;
}
需要使用!==符号
因为大部分情况 表单提交的数据都是字符串