Skip to content

Commit a59c933

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix exception handling in array_multisort()
2 parents 32968f8 + 0ee4371 commit a59c933

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Exception handling in array_multisort()
3+
--FILE--
4+
<?php
5+
$array = [1 => new DateTime(), 0 => new DateTime()];
6+
array_multisort($array, SORT_STRING);
7+
?>
8+
--EXPECTF--
9+
Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in %s:%d
10+
Stack trace:
11+
#0 %s(%d): array_multisort(Array, 2)
12+
#1 {main}
13+
thrown in %s on line %d

ext/standard/array.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5812,6 +5812,9 @@ PHP_FUNCTION(array_multisort)
58125812

58135813
/* Do the actual sort magic - bada-bim, bada-boom. */
58145814
zend_sort(indirect, array_size, sizeof(Bucket *), php_multisort_compare, (swap_func_t)array_bucket_p_sawp);
5815+
if (EG(exception)) {
5816+
goto clean_up;
5817+
}
58155818

58165819
/* Restructure the arrays based on sorted indirect - this is mostly taken from zend_hash_sort() function. */
58175820
for (i = 0; i < num_arrays; i++) {
@@ -5841,15 +5844,15 @@ PHP_FUNCTION(array_multisort)
58415844
}
58425845
}
58435846
}
5847+
RETVAL_TRUE;
58445848

5845-
/* Clean up. */
5849+
clean_up:
58465850
for (i = 0; i < array_size; i++) {
58475851
efree(indirect[i]);
58485852
}
58495853
efree(indirect);
58505854
efree(func);
58515855
efree(arrays);
5852-
RETURN_TRUE;
58535856
}
58545857
/* }}} */
58555858

0 commit comments

Comments
 (0)