Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Zend/tests/array_multisort_exception.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Exception handling in array_multisort()
--FILE--
<?php
$array = [1 => 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
7 changes: 5 additions & 2 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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;
}
/* }}} */

Expand Down