Bug #80346 [NEW]: Function `array_intersect_ukey` not working (really!)
From: gilperon at gmail dot com
Operating system: ALL
PHP version: 7.4.12
Package: *General Issues
Bug Type: Bug
Bug description:Function array_intersect_ukey not working (really!)
Description:
------------
Run the test script. It has 2 arrays in such a way that only the key 4
appears on both. Using array_intersect_ukey does not return 4,
instead it returns array(0) {}. Using array_intersect_key works
perfectly. I also realized there is a bug in the implementation of this
function, because if you run the test script it will show you this:
|4|6|DIFFERENT
|8|6|DIFFERENT
|4|8|DIFFERENT
|3|4|DIFFERENT
|5|4|DIFFERENT
|3|5|DIFFERENT
|6|4|DIFFERENT
|6|5|DIFFERENT
|6|3|DIFFERENT
It shouldnt be comparing 8 with 6 because these keys only appear on the
1st array and these keys shouldnt be compared at all. You can clearly
see that this function, instead of comparing each key of the first array
with each key of the second array, it's comparing the keys from the
first array WITH ITSELF and then comparing the keys of the second array
ITSELF (line |3|5|) and only then comparing the keys of both arrays
together (but for some reason it misses the |4|4|).
I know that in my simple use case I should be using
array_intersect_key but I really need array_intersect_ukey to work
properly because I have a much more complex use case for it.
Test script:
---------------
<?php
$array1 = array(4 => true, 6 => true, 8 => true);
$array2 = array(3 => true, 4 => true, 5 => true);
var_dump(array_intersect_ukey(
$array1,
$array2,
function ($key1, $key2) {
echo "|" . $key1 . "|" . $key2 . "|";
if ($key1 === $key2) {
echo "EQUAL\n";
return 0;
}
else{
echo "DIFFERENT\n";
return 1;
}
}
));
?>
Expected result:
----------------
It should only show the element 4, which is present in both arrays.
Actual result:
--------------
Nothing is returned from the intersection.
--
Edit bug report at https://bugs.php.net/bug.php?id=80346&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80346&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80346&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80346&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80346&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80346&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80346&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80346&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80346&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80346&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80346&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80346&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80346&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80346&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80346&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80346&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80346&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80346&r=mysqlcfg
Thread (2 messages)
- gilperon at gmail dot com