diff options
author | Andrey Hristov <andrey@php.net> | 2004-07-11 19:20:05 +0000 |
---|---|---|
committer | Andrey Hristov <andrey@php.net> | 2004-07-11 19:20:05 +0000 |
commit | 268d3d7ba3d7f2fe3e2f0bf1b8f3536c7cf704ea (patch) | |
tree | 12cf8df66ac1e78e4e42517165ee3130b8c7f003 | |
parent | bc69bdb01ac72542a0087c05e6b4d59965023c01 (diff) | |
download | php-git-268d3d7ba3d7f2fe3e2f0bf1b8f3536c7cf704ea.tar.gz |
fixing bug #28739
array_*diff() and array_*intersect() not clearing the fci cache before work.
FCI call cache was introduced in HEAD. All functions that perform sorting
of arrays clear the fci cache before work. array_*diff() and\ array_*intersect()
were somehow missed to be updated.
-rw-r--r-- | ext/standard/array.c | 14 | ||||
-rw-r--r-- | ext/standard/tests/array/bug28739.phpt | 58 |
2 files changed, 71 insertions, 1 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index b7a690b899..bc253c67e0 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2758,6 +2758,12 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int } old_compare_func = BG(user_compare_func_name); + /* clear FCI cache otherwise : for example the same or other array with + (partly) the same key values has been sorted with uasort() or + other sorting function the comparison is cached, however the the name + of the function for comparison is not respected. see bug #28739 + */ + BG(user_compare_fci_cache) = empty_fcall_info_cache; if (behavior == INTERSECT_NORMAL) { intersect_key_compare_func = array_key_compare; @@ -2785,7 +2791,7 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int return; } efree(callback_name); - + BG(user_compare_func_name) = args[arr_argc]; } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_compare_type is %d. This should never happen. Please report as a bug", data_compare_type); @@ -3106,6 +3112,12 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ } old_compare_func = BG(user_compare_func_name); + /* clear FCI cache otherwise : for example the same or other array with + (partly) the same key values has been sorted with uasort() or + other sorting function the comparison is cached, however the the name + of the function for comparison is not respected. see bug #28739 + */ + BG(user_compare_fci_cache) = empty_fcall_info_cache; if (behavior == DIFF_NORMAL) { diff_key_compare_func = array_key_compare; diff --git a/ext/standard/tests/array/bug28739.phpt b/ext/standard/tests/array/bug28739.phpt new file mode 100644 index 0000000000..af888918c5 --- /dev/null +++ b/ext/standard/tests/array/bug28739.phpt @@ -0,0 +1,58 @@ +--TEST-- +Bug #28739 (*diff() and *intersect() not clearing the fci cache before work) +--FILE-- +<?php +class p { + public $x; + function __construct($x){$this->x=$x;} +} +function a(&$a, &$b){var_dump(__FUNCTION__);return $a->x - $b->x;} +function b(&$a, &$b){var_dump(__FUNCTION__);return $a->x - $b->x;} + +$p1 = array(new p(2), new p(1), new p(0)); +$p2 = array(new p(0), new p(2), new p(3)); + +uasort($p1, 'a'); +print_r($p1); +echo "Now diffing:\n"; +print_r(array_udiff($p1,$p2, 'b')); +?> +--EXPECT-- +string(1) "a" +string(1) "a" +Array +( + [2] => p Object + ( + [x] => 0 + ) + + [1] => p Object + ( + [x] => 1 + ) + + [0] => p Object + ( + [x] => 2 + ) + +) +Now diffing: +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +Array +( + [1] => p Object + ( + [x] => 1 + ) + +)
\ No newline at end of file |