Skip to content

Change Errors to ValueError #4930

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

Closed
wants to merge 2 commits into from
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
34 changes: 17 additions & 17 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ PHP_FUNCTION(min)
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 0)) != NULL) {
ZVAL_COPY_DEREF(return_value, result);
} else {
zend_throw_error(NULL, "Array must contain at least one element");
zend_value_error("Array must contain at least one element");
return;
}
}
Expand Down Expand Up @@ -1310,7 +1310,7 @@ PHP_FUNCTION(max)
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 1)) != NULL) {
ZVAL_COPY_DEREF(return_value, result);
} else {
zend_throw_error(NULL, "Array must contain at least one element");
zend_value_error("Array must contain at least one element");
return;
}
}
Expand Down Expand Up @@ -2451,18 +2451,18 @@ PHP_FUNCTION(extract)
extract_type &= 0xff;

if (extract_type < EXTR_OVERWRITE || extract_type > EXTR_IF_EXISTS) {
zend_throw_error(NULL, "Invalid extract type");
zend_value_error("Invalid extract type");
return;
}

if (extract_type > EXTR_SKIP && extract_type <= EXTR_PREFIX_IF_EXISTS && ZEND_NUM_ARGS() < 3) {
zend_throw_error(NULL, "Specified extract type requires the prefix parameter");
zend_value_error("Specified extract type requires the prefix parameter");
return;
}

if (prefix) {
if (ZSTR_LEN(prefix) && !php_valid_var_name(ZSTR_VAL(prefix), ZSTR_LEN(prefix))) {
zend_throw_error(NULL, "Prefix is not a valid identifier");
zend_value_error("Prefix is not a valid identifier");
return;
}
}
Expand Down Expand Up @@ -2619,7 +2619,7 @@ PHP_FUNCTION(array_fill)

if (EXPECTED(num > 0)) {
if (sizeof(num) > 4 && UNEXPECTED(EXPECTED(num > 0x7fffffff))) {
zend_throw_error(NULL, "Too many elements");
zend_value_error("Too many elements");
return;
} else if (UNEXPECTED(start_key > ZEND_LONG_MAX - num + 1)) {
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
Expand Down Expand Up @@ -2668,7 +2668,7 @@ PHP_FUNCTION(array_fill)
} else if (EXPECTED(num == 0)) {
RETURN_EMPTY_ARRAY();
} else {
zend_throw_error(NULL, "Number of elements can't be negative");
zend_value_error("Number of elements can't be negative");
return;
}
}
Expand Down Expand Up @@ -2706,7 +2706,7 @@ PHP_FUNCTION(array_fill_keys)
#define RANGE_CHECK_DOUBLE_INIT_ARRAY(start, end) do { \
double __calc_size = ((start - end) / step) + 1; \
if (__calc_size >= (double)HT_MAX_SIZE) { \
zend_throw_error(NULL, \
zend_value_error(\
"The supplied range exceeds the maximum array size: start=%0.0f end=%0.0f", end, start); \
return; \
} \
Expand All @@ -2718,7 +2718,7 @@ PHP_FUNCTION(array_fill_keys)
#define RANGE_CHECK_LONG_INIT_ARRAY(start, end) do { \
zend_ulong __calc_size = ((zend_ulong) start - end) / lstep; \
if (__calc_size >= HT_MAX_SIZE - 1) { \
zend_throw_error(NULL, \
zend_value_error(\
"The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT, end, start); \
return; \
} \
Expand Down Expand Up @@ -2816,7 +2816,7 @@ PHP_FUNCTION(range)
high = zval_get_double(zhigh);

if (zend_isinf(high) || zend_isinf(low)) {
zend_throw_error(NULL, "Invalid range supplied: start=%0.0f end=%0.0f", low, high);
zend_value_error("Invalid range supplied: start=%0.0f end=%0.0f", low, high);
return;
}

Expand Down Expand Up @@ -2909,7 +2909,7 @@ PHP_FUNCTION(range)
}
err:
if (err) {
zend_throw_error(NULL, "step exceeds the specified range");
zend_value_error("Step exceeds the specified range");
return;
}
}
Expand Down Expand Up @@ -4389,7 +4389,7 @@ PHP_FUNCTION(array_pad)
input_size = zend_hash_num_elements(Z_ARRVAL_P(input));
pad_size_abs = ZEND_ABS(pad_size);
if (pad_size_abs < 0 || pad_size_abs - input_size > Z_L(1048576)) {
zend_throw_error(NULL, "You may only pad up to 1048576 elements at a time");
zend_value_error("You may only pad up to 1048576 elements at a time");
return;
}

Expand Down Expand Up @@ -5769,7 +5769,7 @@ PHP_FUNCTION(array_multisort)
array_size = zend_hash_num_elements(Z_ARRVAL_P(arrays[0]));
for (i = 0; i < num_arrays; i++) {
if (zend_hash_num_elements(Z_ARRVAL_P(arrays[i])) != (uint32_t)array_size) {
zend_throw_error(NULL, "Array sizes are inconsistent");
zend_value_error("Array sizes are inconsistent");
MULTISORT_ABORT;
}
}
Expand Down Expand Up @@ -5865,7 +5865,7 @@ PHP_FUNCTION(array_rand)
num_avail = zend_hash_num_elements(Z_ARRVAL_P(input));

if (num_avail == 0) {
zend_throw_error(NULL, "Array is empty");
zend_value_error("Array is empty");
return;
}

Expand Down Expand Up @@ -5906,7 +5906,7 @@ PHP_FUNCTION(array_rand)
}

if (num_req <= 0 || num_req > num_avail) {
zend_throw_error(NULL, "Second argument has to be between 1 and the number of elements in the array");
zend_value_error("Second argument has to be between 1 and the number of elements in the array");
return;
}

Expand Down Expand Up @@ -6395,7 +6395,7 @@ PHP_FUNCTION(array_chunk)

/* Do bounds checking for size parameter. */
if (size < 1) {
zend_throw_error(NULL, "Size parameter expected to be greater than 0");
zend_value_error("Size parameter expected to be greater than 0");
return;
}

Expand Down Expand Up @@ -6460,7 +6460,7 @@ PHP_FUNCTION(array_combine)
num_values = zend_hash_num_elements(values);

if (num_keys != num_values) {
zend_throw_error(NULL, "Both parameters should have an equal number of elements");
zend_value_error("Both parameters should have an equal number of elements");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ PHP_FUNCTION(assert_options)
break;

default:
zend_throw_error(NULL, "Unknown value " ZEND_LONG_FMT, what);
zend_value_error("Unknown value " ZEND_LONG_FMT, what);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ PHP_FUNCTION(scandir)
ZEND_PARSE_PARAMETERS_END();

if (dirn_len < 1) {
zend_throw_error(NULL, "Directory name cannot be empty");
zend_value_error("Directory name cannot be empty");
return;
}

Expand Down
24 changes: 12 additions & 12 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,12 +931,12 @@ PHP_FUNCTION(wordwrap)
}

if (breakchar_len == 0) {
zend_throw_error(NULL, "Break string cannot be empty");
zend_value_error("Break string cannot be empty");
return;
}

if (linelength == 0 && docut) {
zend_throw_error(NULL, "Can't force cut when width is zero");
zend_value_error("Can't force cut when width is zero");
return;
}

Expand Down Expand Up @@ -1143,7 +1143,7 @@ PHP_FUNCTION(explode)
ZEND_PARSE_PARAMETERS_END();

if (ZSTR_LEN(delim) == 0) {
zend_throw_error(NULL, "Empty delimiter");
zend_value_error("Empty delimiter");
return;
}

Expand Down Expand Up @@ -1642,7 +1642,7 @@ PHP_FUNCTION(dirname)
ZSTR_LEN(ret) = zend_dirname(ZSTR_VAL(ret), str_len);
#endif
} else if (levels < 1) {
zend_throw_error(NULL, "Invalid argument, levels must be >= 1");
zend_value_error("Invalid argument, levels must be >= 1");
zend_string_efree(ret);
return;
} else {
Expand Down Expand Up @@ -2155,7 +2155,7 @@ PHP_FUNCTION(chunk_split)
ZEND_PARSE_PARAMETERS_END();

if (chunklen <= 0) {
zend_throw_error(NULL, "Chunk length should be greater than zero");
zend_value_error("Chunk length should be greater than zero");
return;
}

Expand Down Expand Up @@ -5322,7 +5322,7 @@ PHP_FUNCTION(str_repeat)
ZEND_PARSE_PARAMETERS_END();

if (mult < 0) {
zend_throw_error(NULL, "Second argument has to be greater than or equal to 0");
zend_value_error("Second argument has to be greater than or equal to 0");
return;
}

Expand Down Expand Up @@ -5569,7 +5569,7 @@ PHP_FUNCTION(substr_count)
ZEND_PARSE_PARAMETERS_END();

if (needle_len == 0) {
zend_throw_error(NULL, "Empty substring");
zend_value_error("Empty substring");
return;
}

Expand Down Expand Up @@ -5646,12 +5646,12 @@ PHP_FUNCTION(str_pad)
}

if (pad_str_len == 0) {
zend_throw_error(NULL, "Padding string cannot be empty");
zend_value_error("Padding string cannot be empty");
return;
}

if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH) {
zend_throw_error(NULL, "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH");
zend_value_error("Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH");
return;
}

Expand Down Expand Up @@ -5911,7 +5911,7 @@ PHP_FUNCTION(str_word_count)
/* nothing to be done */
break;
default:
zend_throw_error(NULL, "Invalid format value " ZEND_LONG_FMT, type);
zend_value_error("Invalid format value " ZEND_LONG_FMT, type);
return;
}

Expand Down Expand Up @@ -6028,7 +6028,7 @@ PHP_FUNCTION(str_split)
ZEND_PARSE_PARAMETERS_END();

if (split_length <= 0) {
zend_throw_error(NULL, "The length of each segment must be greater than zero");
zend_value_error("The length of each segment must be greater than zero");
return;
}

Expand Down Expand Up @@ -6107,7 +6107,7 @@ PHP_FUNCTION(substr_compare)
if (len == 0) {
RETURN_LONG(0L);
} else {
zend_throw_error(NULL, "The length must be greater than or equal to zero");
zend_value_error("The length must be greater than or equal to zero");
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/array/array_chunk2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ $input_array = array('a', 'b', 'c', 'd', 'e');

try {
var_dump(array_chunk($input_array, 0));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}

try {
var_dump(array_chunk($input_array, 0, true));
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}

Expand Down
9 changes: 3 additions & 6 deletions ext/standard/tests/array/array_chunk_variation5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,22 @@ foreach ($sizes as $size){
echo "\n-- Testing array_chunk() when size = $size --\n";
try {
var_dump( array_chunk($input_array, $size) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump( array_chunk($input_array, $size, true) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump( array_chunk($input_array, $size, false) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
}
?>

DONE
--EXPECT--
*** Testing array_chunk() : usage variations ***

Expand Down Expand Up @@ -146,5 +145,3 @@ array(3) {
int(3)
}
}

DONE
9 changes: 3 additions & 6 deletions ext/standard/tests/array/array_combine_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,27 @@ var_dump( array_combine(array(), array()) );
echo "\n-- Testing array_combine() function with empty array for \$keys argument --\n";
try {
var_dump( array_combine(array(), array(1, 2)) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage();
}

// Testing array_combine by passing empty array to $values
echo "\n-- Testing array_combine() function with empty array for \$values argument --\n";
try {
var_dump( array_combine(array(1, 2), array()) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage();
}

// Testing array_combine with arrays having unequal number of elements
echo "\n-- Testing array_combine() function by passing array with unequal number of elements --\n";
try {
var_dump( array_combine(array(1, 2), array(1, 2, 3)) );
} catch (\Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage();
}

?>

DONE
--EXPECT--
*** Testing array_combine() : error conditions specific to array_combine() ***

Expand All @@ -54,4 +52,3 @@ Both parameters should have an equal number of elements
Both parameters should have an equal number of elements
-- Testing array_combine() function by passing array with unequal number of elements --
Both parameters should have an equal number of elements
DONE
8 changes: 2 additions & 6 deletions ext/standard/tests/array/array_fill_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ $val = 1;

try {
var_dump( array_fill($start_key,$num,$val) );
} catch (Error $e) {
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}

?>

DONE
--EXPECTF--
--EXPECT--
*** Testing array_fill() : error conditions ***
Number of elements can't be negative

DONE
4 changes: 2 additions & 2 deletions ext/standard/tests/array/array_multisort_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ echo "\n-- Testing array_multisort() function with repeated flags --\n";
$ar1 = array(1);
try {
var_dump( array_multisort($ar1, SORT_ASC, SORT_ASC) );
} catch (Error $e) {
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}

echo "\n-- Testing array_multisort() function with repeated flags --\n";
$ar1 = array(1);
try {
var_dump( array_multisort($ar1, SORT_STRING, SORT_NUMERIC) );
} catch (Error $e) {
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/array/array_multisort_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ foreach($inputs as $key =>$value) {
echo "\n--$key--\n";
try {
var_dump( array_multisort($value));
} catch (Error $e) {
} catch (\ValueError | \TypeError $e) {
echo $e->getMessage() . "\n";
}
};
Expand Down
Loading