php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72805 array diff bug
Submitted: 2016-08-10 14:12 UTC Modified: 2016-08-10 21:01 UTC
From: mitrickx at mail dot ru Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS: Windows,Debian
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mitrickx at mail dot ru
New email:
PHP Version: OS:

 

 [2016-08-10 14:12 UTC] mitrickx at mail dot ru
Description:
------------
$item = array (
    'id' => '21',
    'sid' => NULL,
	'parent_id' => '20',
	'storage_id' => '10',
	'name' => 'a_folder_filesFileModelTesttestMoveSmallTreeIntoFolder57ab2d09bfa17',
	'left_key' => '4',
	'right_key' => '5',
	'depth' => '1',
	'contact_id' => '504',
	'size' => '0',
	'count' => '1',
	'ext' => NULL,
	'type' => 'folder',
	'create_datetime' => '2016-08-10 16:32:57',
	'update_datetime' => '2016-08-10 16:32:57',
	'hash' => '75eaadd1fbbd5ecf467f7e7bc2bd8e61',
	'source_id' => '4',
	'source_inner_id' => NULL,
	'source_path' => NULL,
	'mark' => NULL,
	'in_copy_process' => '0',
);
$prev_item =   array (
    'id' => '21',
    'sid' => NULL,
    'parent_id' => '20',
    'storage_id' => '10',
    'name' => 'a_folder_filesFileModelTesttestMoveSmallTreeIntoFolder57ab2d09bfa17',
    'left_key' => '4',
    'right_key' => '5',
    'depth' => '1',
    'contact_id' => '504',
    'size' => '0',
    'count' => '1',
    'ext' => NULL,
    'type' => 'folder',
    'create_datetime' => '2016-08-10 16:32:57',
    'update_datetime' => '2016-08-10 16:32:57',
    'hash' => NULL,
    'source_id' => '0',
    'source_inner_id' => NULL,
    'source_path' => NULL,
    'mark' => NULL,
    'in_copy_process' => '0',
);

var_dump(array_diff($item, $prev_item));

// Incorrect!
// Array
// (
//     hash => '75eaadd1fbbd5ecf467f7e7bc2bd8e61'
//  )

// Must be
// Array
// (
//     hash => '75eaadd1fbbd5ecf467f7e7bc2bd8e61'
//     source_id => '4'
//  )

// but when we change a little. 'source_id' was '4', now it is '6'
$item['source_id'] = '6';

var_dump(array_diff($item, $prev_item));

// Correct
// Array
// (
//   hash => '75eaadd1fbbd5ecf467f7e7bc2bd8e61'
//   source_id => '6'
// )

// and come back to '4' again
$item['source_id'] = '4';

// Tada!! Lol!! :) Incorrect again
// Array
// (
//   hash => '75eaadd1fbbd5ecf467f7e7bc2bd8e61'
// )


// just play with digits. Try '1', '2', '3', '4', '5', '6'


Test script:
---------------
// See bellow


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-10 14:28 UTC] mitrickx at mail dot ru
-Status: Open +Status: Closed
 [2016-08-10 14:28 UTC] mitrickx at mail dot ru
Sorry. My mistake
 [2016-08-10 21:01 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 04:00:02 2026 UTC