Doc #69059 [Fbk->NoF]: array_udiff logical bug
| From: | php-bugs at lists dot php dot net | Date: | Sun, 01 Mar 2015 04:22:20 +0000 |
| Subject: | Doc #69059 [Fbk->NoF]: array_udiff logical bug | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-11980@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69059&edit=1
ID: 69059
Updated by: php-bugs@lists.php.net
Reported by: geoleu11 at gmail dot com
Summary: array_udiff logical bug
-Status: Feedback
+Status: No Feedback
Type: Documentation Problem
Package: *General Issues
Operating System: Ubuntu
PHP Version: Irrelevant
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2015-02-16 15:33:46] geoleu11 at gmail dot com
Yes, I saw that if you return unsigned integer the sort/looping is different. That is why I said
there is a logical bug. The result should be the same no matter if you use unsigned/signed negative
integer. It should be a simple comparison : are those 2 values equal or unequal. This is a good way
to properly compare array of objects. I ended up using a php made version of array_udiff.
Is 'red' > || < 'blue'? It's not about counting the bits, it's
simply about checking for equality.
Having a logic/scenario for 3 type of returns seems prone to bugs (at least in my case was). That is
why array_udiff should treat negative int and unsigned int the same. So basically one scenario for 0
and one for negative/unsigned int.
If there is a fix relating to this function in the current php dev version, a documentation update
would be nice that explains how negative int is treated compared to a unsinged int for the callback
function.
Thanks
------------------------------------------------------------------------
[2015-02-16 03:38:53] laruence@php.net
s ,bug,issue,
------------------------------------------------------------------------
[2015-02-16 03:38:15] laruence@php.net
compare function should return value greater than 0 if $a > $b, less than 0 if $b < $a.
thus, your codes should be:
<?php
$a1 = array('red');
$a2 = array('red', 'blue');
$diff = array_udiff($a1, $a2,
function($a, $b) {
if($a === $b) {
return 0;
}
else {
return $a > $b? 1 : -1;
}
});
var_dump($diff);
anyway, this bug doesn't exists in master because new sort algo impelemented.
thanks
------------------------------------------------------------------------
[2015-02-16 01:03:04] geoleu11 at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.array-udiff
---
Since the information that can be selected for providing php version information, here is some info
about the build : PHP Version 5.5.9-1ubuntu4.5 .
Also regarding the problem/bug source : array function, more specifically : array_udiff .
The output of the below script is :
array (size=1)
0 => string 'red' (length=3)
Why does array_udiff return a common element from those arrays? Shouldn't it return the
elements are present in the first array and not in the other arrays?
At least if you try internal array_diff, it does return the proper value from those 2 arrays below .
Test script:
---------------
$a1 = array('red');
$a2 = array('red', 'blue');
$diff = array_udiff($a1, $a2,
function($a, $b) {
if($a === $b) {
return 0;
}
else {
return -1;
}
});
var_dump($diff);
Expected result:
----------------
The expected result should be an empty array.
array (size=0)
empty
Actual result:
--------------
array (size=1)
0 => string 'red' (length=3)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69059&edit=1