diff --git a/Zend/tests/array_multisort_exception.phpt b/Zend/tests/array_multisort_exception.phpt new file mode 100644 index 0000000000000..8ee6007745e03 --- /dev/null +++ b/Zend/tests/array_multisort_exception.phpt @@ -0,0 +1,13 @@ +--TEST-- +Exception handling in array_multisort() +--FILE-- + new DateTime(), 0 => new DateTime()]; +array_multisort($array, SORT_STRING); +?> +--EXPECTF-- +Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in %s:%d +Stack trace: +#0 %s(%d): array_multisort(Array, 2) +#1 {main} + thrown in %s on line %d diff --git a/ext/standard/array.c b/ext/standard/array.c index fb705cd34c4e8..87eea28d48f21 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -5589,6 +5589,9 @@ PHP_FUNCTION(array_multisort) /* Do the actual sort magic - bada-bim, bada-boom. */ zend_sort(indirect, array_size, sizeof(Bucket *), php_multisort_compare, (swap_func_t)array_bucket_p_sawp); + if (EG(exception)) { + goto clean_up; + } /* Restructure the arrays based on sorted indirect - this is mostly taken from zend_hash_sort() function. */ for (i = 0; i < num_arrays; i++) { @@ -5614,15 +5617,15 @@ PHP_FUNCTION(array_multisort) zend_hash_rehash(hash); } } + RETVAL_TRUE; - /* Clean up. */ +clean_up: for (i = 0; i < array_size; i++) { efree(indirect[i]); } efree(indirect); efree(func); efree(arrays); - RETURN_TRUE; } /* }}} */