Bug #72805 [NEW]: array diff bug

From: Date: Wed, 10 Aug 2016 14:12:16 +0000
Subject: Bug #72805 [NEW]: array diff bug
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203166@lists.php.net to get a copy of this message
From:             mitrickx at mail dot ru
Operating system: Windows,Debian
PHP version:      Irrelevant
Package:          *General Issues
Bug Type:         Bug
Bug description:array diff bug

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


-- 
Edit bug report at https://bugs.php.net/bug.php?id=72805&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72805&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72805&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72805&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72805&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72805&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72805&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72805&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72805&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72805&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72805&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72805&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72805&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72805&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72805&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72805&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72805&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72805&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72805&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72805&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72805&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#203166) next »