@@ -6038,7 +6038,7 @@ PHP_FUNCTION(array_multisort)
60386038 for (i = 0 ; i < MULTISORT_LAST ; i ++ ) {
60396039 parse_state [i ] = 0 ;
60406040 }
6041- func = ARRAYG ( multisort_func ) = ecalloc (argc , sizeof (bucket_compare_func_t ));
6041+ func = ecalloc (argc , sizeof (bucket_compare_func_t ));
60426042
60436043 /* Here we go through the input arguments and parse them. Each one can
60446044 * be either an array or a sort flag which follows an array. If not
@@ -6054,7 +6054,7 @@ PHP_FUNCTION(array_multisort)
60546054 /* We see the next array, so we update the sort flags of
60556055 * the previous array and reset the sort flags. */
60566056 if (i > 0 ) {
6057- ARRAYG ( multisort_func ) [num_arrays - 1 ] = php_get_data_compare_func_unstable (sort_type , sort_order != PHP_SORT_ASC );
6057+ func [num_arrays - 1 ] = php_get_data_compare_func_unstable (sort_type , sort_order != PHP_SORT_ASC );
60586058 sort_order = PHP_SORT_ASC ;
60596059 sort_type = PHP_SORT_REGULAR ;
60606060 }
@@ -6106,8 +6106,6 @@ PHP_FUNCTION(array_multisort)
61066106 MULTISORT_ABORT ;
61076107 }
61086108 }
6109- /* Take care of the last array sort flags. */
6110- ARRAYG (multisort_func )[num_arrays - 1 ] = php_get_data_compare_func_unstable (sort_type , sort_order != PHP_SORT_ASC );
61116109
61126110 /* Make sure the arrays are of the same size. */
61136111 array_size = zend_hash_num_elements (Z_ARRVAL_P (arrays [0 ]));
@@ -6125,6 +6123,11 @@ PHP_FUNCTION(array_multisort)
61256123 RETURN_TRUE ;
61266124 }
61276125
6126+ /* Take care of the last array sort flags. */
6127+ func [num_arrays - 1 ] = php_get_data_compare_func_unstable (sort_type , sort_order != PHP_SORT_ASC );
6128+ bucket_compare_func_t * old_multisort_func = ARRAYG (multisort_func );
6129+ ARRAYG (multisort_func ) = func ;
6130+
61286131 /* Create the indirection array. This array is of size MxN, where
61296132 * M is the number of entries in each input array and N is the number
61306133 * of the input arrays + 1. The last column is UNDEF to indicate the end
@@ -6201,6 +6204,7 @@ PHP_FUNCTION(array_multisort)
62016204 efree (indirect );
62026205 efree (func );
62036206 efree (arrays );
6207+ ARRAYG (multisort_func ) = old_multisort_func ;
62046208}
62056209/* }}} */
62066210
0 commit comments