Skip to content

Fix array_udiff_assoc() and array_uintersect_assoc() clobbering the user comparison callback - #24453

Open
lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/array-assoc-user-compare-restore
Open

lacatoire wants to merge 1 commit into
php:PHP-8.4from
lacatoire:fix/array-assoc-user-compare-restore

Conversation

@lacatoire

@lacatoire lacatoire commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

array_udiff_assoc() and array_uintersect_assoc() parse the callback straight into BG(user_compare_fci) and never restore the previous value, unlike the other array_u*() functions. A comparison callback that calls one of them is replaced by the inner callback for the rest of the sort.

Split out of #24426, where the review pointed out these two functions.

To reproduce on PHP 8.4

<?php
$sorted = [3, 1, 2];
usort($sorted, function ($a, $b) {
    echo "outer\n";
    array_udiff_assoc([1], [1], function ($x, $y) { echo "inner\n"; return $x <=> $y; });
    return $a <=> $b;
});

Before: outer inner inner inner (the outer comparator is replaced after the first call)

After: outer inner outer inner outer inner

…ser comparison callback

php_array_diff_key() and php_array_intersect_key() parse the callback straight
into BG(user_compare_fci) without saving the previous value, unlike the other
array_u*() functions. A comparison callback that calls one of them is replaced
by the inner callback for the rest of the sort.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant