Skip to content
Merged
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ PHP NEWS
. Add enum SortDirection. (timwolla)
. pathinfo() raises a ValueError with an invalid $flags argument.
(David Carlier)
. Passing an invalid flag value to the second argument of scandir() will now
throw a ValueError. (alexandre-daubois)

- Streams:
. Added so_keepalive, tcp_keepidle, tcp_keepintvl and tcp_keepcnt stream
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ PHP 8.6 UPGRADE NOTES
- Standard:
. pathinfo() now raises a ValueError when an invalid $flag argument
value is passed.
. scandir() now raises a ValueError when an invalid $sorting_order
argument value is passed.

- Zip:
. ZipArchive::extractTo now raises a TypeError for the
Expand Down
9 changes: 7 additions & 2 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -4799,21 +4799,26 @@ PHP_FUNCTION(array_change_key_case)
zend_string *string_key;
zend_string *new_key;
zend_ulong num_key;
zend_long change_to_upper=0;
zend_long change_to_upper = PHP_CASE_LOWER;

ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_ARRAY(array)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(change_to_upper)
ZEND_PARSE_PARAMETERS_END();

if (change_to_upper != PHP_CASE_LOWER && change_to_upper != PHP_CASE_UPPER) {
zend_argument_value_error(2, "must be either CASE_LOWER or CASE_UPPER");
RETURN_THROWS();
}

array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(array)));

ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, entry) {
if (!string_key) {
entry = zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
} else {
if (change_to_upper) {
if (change_to_upper == PHP_CASE_UPPER) {
new_key = zend_string_toupper(string_key);
} else {
new_key = zend_string_tolower(string_key);
Expand Down
8 changes: 6 additions & 2 deletions ext/standard/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,13 @@ PHP_FUNCTION(scandir)
n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasort);
} else if (flags == PHP_SCANDIR_SORT_NONE) {
n = php_stream_scandir(dirn, &namelist, context, NULL);
} else {
} else if (flags == PHP_SCANDIR_SORT_DESCENDING) {
n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasortr);
}
} else {
zend_argument_value_error(2, "must be one of the SCANDIR_SORT_ASCENDING, SCANDIR_SORT_DESCENDING, or SCANDIR_SORT_NONE constants");
RETURN_THROWS();
}

if (n < 0) {
php_error_docref(NULL, E_WARNING, "(errno %d): %s", errno, strerror(errno));
RETURN_FALSE;
Expand Down
14 changes: 14 additions & 0 deletions ext/standard/tests/array/array_change_key_case_flag_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
array_change_key_case(): invalid $case argument
--FILE--
<?php

try {
array_change_key_case([], -10);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
ValueError: array_change_key_case(): Argument #2 ($case) must be either CASE_LOWER or CASE_UPPER
50 changes: 0 additions & 50 deletions ext/standard/tests/array/array_change_key_case_variation.phpt

This file was deleted.

132 changes: 0 additions & 132 deletions ext/standard/tests/array/array_change_key_case_variation4.phpt

This file was deleted.

12 changes: 12 additions & 0 deletions ext/standard/tests/dir/scandir_invalid_flag.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Provide wrong flags to scandir()
--FILE--
<?php
try {
scandir('something', -1);
} catch (ValueError $e) {
echo $e->getMessage() . "\n";
}
?>
--EXPECT--
scandir(): Argument #2 ($sorting_order) must be one of the SCANDIR_SORT_ASCENDING, SCANDIR_SORT_DESCENDING, or SCANDIR_SORT_NONE constants
71 changes: 0 additions & 71 deletions ext/standard/tests/dir/scandir_variation9-win32-mb.phpt

This file was deleted.

Loading