think-orm icon indicating copy to clipboard operation
think-orm copied to clipboard

save方法判断更新的数据时判断的问题

Open eryunser opened this issue 4 years ago • 1 comments

image 图中代码在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;
    }

需要使用!==符号

eryunser avatar Feb 23 '21 07:02 eryunser

因为大部分情况 表单提交的数据都是字符串

liu21st avatar Feb 24 '21 07:02 liu21st