From 239ad5c55d8d5b09ec87fcf125e5dbe746a64842 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 8 Feb 2021 10:13:29 -0800 Subject: [PATCH] In "array_mergev()", guarantee the "call_user_func_array()" parameter list is a natrual list Summary: Ref T13588. The behavior of "call_user_func_array()" has changed in PHP8, and the function now attempts to use array keys as argument names. This always fails when calling "array_merge()" (which does not accept named parameters), and may cause misbehavior in the general case. Guarantee the argument is a natural list (with keys "0", "1", "2", ...). Test Plan: - Behavior unchanged under PHP7. - User reports fixed behavior under PHP8, see . - See T13588. Maniphest Tasks: T13588 Differential Revision: https://secure.phabricator.com/D21551 --- src/utils/utils.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/utils.php b/src/utils/utils.php index 4c44d7b7..3ae606d7 100644 --- a/src/utils/utils.php +++ b/src/utils/utils.php @@ -876,14 +876,19 @@ function array_mergev(array $arrayv) { if (!is_array($item)) { throw new InvalidArgumentException( pht( - 'Expected all items passed to `%s` to be arrays, but '. + 'Expected all items passed to "array_mergev()" to be arrays, but '. 'argument with key "%s" has type "%s".', - __FUNCTION__.'()', $key, gettype($item))); } } + // See T13588. In PHP8, "call_user_func_array()" will attempt to use + // "unnatural" array keys as named parameters, and then fail because + // "array_merge()" does not accept named parameters . Guarantee the list is + // a "natural" list to avoid this. + $arrayv = array_values($arrayv); + return call_user_func_array('array_merge', $arrayv); }