Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array_change_key_case(): Throw ValueError on invalid argument #15883

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
9 changes: 7 additions & 2 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -4866,21 +4866,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
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.

Loading