Skip to content
Open
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
12 changes: 12 additions & 0 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -4863,6 +4863,18 @@ PHP_FUNCTION(array_unique)
return;
}

zend_long base_sort = sort_type & ~PHP_SORT_FLAG_CASE;

if (base_sort != PHP_SORT_REGULAR
&& base_sort != PHP_SORT_NUMERIC
&& base_sort != PHP_SORT_STRING
&& base_sort != PHP_SORT_LOCALE_STRING) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also SORT_NATURAL. I don't know whether it would differ in behavior from SORT_STRING, but even if it doesn't it should continue to be accepted.


zend_argument_value_error(
2, "must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING");
RETURN_THROWS();
}

if (sort_type == PHP_SORT_STRING) {
HashTable seen;
zend_long num_key;
Expand Down
20 changes: 20 additions & 0 deletions ext/standard/tests/array/array_unique_invalid_sort_type.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
array_unique() throws ValueError on invalid sort_type
--FILE--
<?php
try {
array_unique([1, 2, 3], 999);
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
array_unique([1, 2, 3], -1);
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
array_unique(): Argument #2 ($flags) must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING
array_unique(): Argument #2 ($flags) must be one of SORT_REGULAR, SORT_NUMERIC, SORT_STRING, or SORT_LOCALE_STRING

Loading