Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.6.0a3

Bug #6293 array_intersect_key produces incorrect results with more than 2 arguments
Submitted: 2005-12-19 18:20 UTC Modified: 2005-12-29 05:00 UTC
From: court at idstrom dot com Assigned: arpad
Status: Closed Package: PHP_Compat
PHP Version: 5.0.5 OS: Mac OSX 10.4.3
Roadmaps: 1.6.0a1    
Subscription  


 [2005-12-19 18:20 UTC] court at idstrom dot com
Description: ------------ PHP_Compat version 1.5 Test script: --------------- <? require_once('PHP/Compat/Function/array_intersect_key.php'); print_r(array_intersect_key( array('a'=>1, 'b'=>2, 'c'=>3, 'd'=>4), array('a'=>0, 'c'=>0), array('a'=>0, 'd'=>4) )); ?> Here's a correct (and slightly faster) implementation that requires php 4 >= 4.0.4 (for call_user_func_array) function array_intersect_key() { $args = func_get_args(); $arg_keys = array_map('array_keys', $args); $result_keys = call_user_func_array('array_intersect', $arg_keys); $first_arg = $args[0]; $result = array(); foreach($result_keys as $key) { $result[$key] = $first_arg[$key]; } return $result; } } Expected result: ---------------- Array ( [a] => 1 ) Actual result: -------------- Array ( [a] => 1 [c] => 3 [d] => 4 )

Comments

 [2005-12-29 05:00 UTC] arpad
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.