Bug #52867 [Opn->Bgs]: array_intersect_ukey does not check all keys
| From: | iliaa@php.net | Date: | Thu, 25 Nov 2010 19:57:13 +0000 |
| Subject: | Bug #52867 [Opn->Bgs]: array_intersect_ukey does not check all keys | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-156454@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52867&edit=1
ID: 52867
Updated by: iliaa@php.net
Reported by: jason at linuxbox dot com
Summary: array_intersect_ukey does not check all keys
-Status: Open
+Status: Bogus
Type: Bug
Package: Arrays related
Operating System: Linux
PHP Version: 5.3.3
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Previous Comments:
------------------------------------------------------------------------
[2010-10-13 04:17:05] uramihsayibok at gmail dot com
Not a bug.
The manual page for array_intersect_ukey says
>It must return an integer less than, equal to, or greater than zero if
the
>first key is considered to be respectively less than, equal to, or
greater than
>the second.
Your callback does not do that and by violating the postcondition you
get undefined behavior.
function func($key1, $key2) {
// equivalent to 'return strcmp($key1, $key2);'
if ($key1 == $key2) {
return 0;
} else if ($key1 < $key2) {
return -1;
} else /* if ($key1 > $key2) */ {
return 1;
}
}
------------------------------------------------------------------------
[2010-09-17 04:18:19] jason at linuxbox dot com
Description:
------------
The array_intersect_ukey() function appears to have an invalid algorithm
for
iterating over array keys to be passed to the user function. A simple
test case
that implements the same behavior as array_intersect_key() illustrates
the bug.
Test script:
---------------
<?php
function func($key1, $key2) {
if ($key1 == $key2) {
return 0;
}
return 1;
}
$all = array('cat' => 'brown',
'dog' => 'yellow',
'mouse' => 'grey',
'horse' => 'white'
);
$keep = array('dog' => 1, 'horse' => 1);
// Output of the following should be identical
print_r(array_intersect_key($all, $keep));
print_r(array_intersect_ukey($all, $keep, 'func'));
?>
Expected result:
----------------
Array
(
[dog] => yellow
[horse] => white
)
Array
(
[dog] => yellow
[horse] => white
)
Actual result:
--------------
Array
(
[dog] => yellow
[horse] => white
)
Array
(
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52867&edit=1