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

getChangedData() 获取变化的数据 方法错误

Open augushong opened this issue 4 years ago • 1 comments

对于下面这段代码,对比$data$origin,这两个应当是不一样的,但是原有代码认为这两个数据没有变换, 原因是return is_object($a) || $a != $b ? 1 : 0;, 这里的比较应该用强等于,

        $data = [
            'date'=>'2019'
        ];
        $origin = [
            'date'=>'2019.'
        ];

        $result = array_udiff_assoc($data, $origin, function ($a, $b) {

            if ((empty($a) || empty($b)) && $a !== $b) {
                return 1;
            }

            return is_object($a) || $a != $b ? 1 : 0;
            // return is_object($a) || $a !== $b ? 1 : 0;  // 这样就生效了
        });

augushong avatar Sep 28 '21 16:09 augushong

@liu21st 这个问题我也遇到了,这是个bug?还是有意这么设计的?

iwindy avatar Mar 03 '23 06:03 iwindy