@@ -6051,7 +6051,7 @@ PHP_FUNCTION(array_multisort)
60516051 for (i = 0 ; i < MULTISORT_LAST ; i ++ ) {
60526052 parse_state [i ] = 0 ;
60536053 }
6054- func = ARRAYG ( multisort_func ) = ecalloc (argc , sizeof (bucket_compare_func_t ));
6054+ func = ecalloc (argc , sizeof (bucket_compare_func_t ));
60556055
60566056 /* Here we go through the input arguments and parse them. Each one can
60576057 * be either an array or a sort flag which follows an array. If not
@@ -6067,7 +6067,7 @@ PHP_FUNCTION(array_multisort)
60676067 /* We see the next array, so we update the sort flags of
60686068 * the previous array and reset the sort flags. */
60696069 if (i > 0 ) {
6070- ARRAYG ( multisort_func ) [num_arrays - 1 ] = php_get_data_compare_func_unstable (sort_type , sort_order != PHP_SORT_ASC );
6070+ func [num_arrays - 1 ] = php_get_data_compare_func_unstable (sort_type , sort_order != PHP_SORT_ASC );
60716071 sort_order = PHP_SORT_ASC ;
60726072 sort_type = PHP_SORT_REGULAR ;
60736073 }
@@ -6119,8 +6119,6 @@ PHP_FUNCTION(array_multisort)
61196119 MULTISORT_ABORT ;
61206120 }
61216121 }
6122- /* Take care of the last array sort flags. */
6123- ARRAYG (multisort_func )[num_arrays - 1 ] = php_get_data_compare_func_unstable (sort_type , sort_order != PHP_SORT_ASC );
61246122
61256123 /* Make sure the arrays are of the same size. */
61266124 array_size = zend_hash_num_elements (Z_ARRVAL_P (arrays [0 ]));
@@ -6138,6 +6136,11 @@ PHP_FUNCTION(array_multisort)
61386136 RETURN_TRUE ;
61396137 }
61406138
6139+ /* Take care of the last array sort flags. */
6140+ func [num_arrays - 1 ] = php_get_data_compare_func_unstable (sort_type , sort_order != PHP_SORT_ASC );
6141+ bucket_compare_func_t * old_multisort_func = ARRAYG (multisort_func );
6142+ ARRAYG (multisort_func ) = func ;
6143+
61416144 /* Create the indirection array. This array is of size MxN, where
61426145 * M is the number of entries in each input array and N is the number
61436146 * of the input arrays + 1. The last column is UNDEF to indicate the end
@@ -6214,6 +6217,7 @@ PHP_FUNCTION(array_multisort)
62146217 efree (indirect );
62156218 efree (func );
62166219 efree (arrays );
6220+ ARRAYG (multisort_func ) = old_multisort_func ;
62176221}
62186222/* }}} */
62196223
0 commit comments