Skip to content

Commit 31d3167

Browse files
committed
Convert Errors to ValueErrors
1 parent 4845c3f commit 31d3167

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+125
-200
lines changed

ext/standard/array.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ PHP_FUNCTION(min)
12631263
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 0)) != NULL) {
12641264
ZVAL_COPY_DEREF(return_value, result);
12651265
} else {
1266-
zend_throw_error(NULL, "Array must contain at least one element");
1266+
zend_value_error("Array must contain at least one element");
12671267
return;
12681268
}
12691269
}
@@ -1310,7 +1310,7 @@ PHP_FUNCTION(max)
13101310
if ((result = zend_hash_minmax(Z_ARRVAL(args[0]), php_array_data_compare, 1)) != NULL) {
13111311
ZVAL_COPY_DEREF(return_value, result);
13121312
} else {
1313-
zend_throw_error(NULL, "Array must contain at least one element");
1313+
zend_value_error("Array must contain at least one element");
13141314
return;
13151315
}
13161316
}
@@ -2451,18 +2451,18 @@ PHP_FUNCTION(extract)
24512451
extract_type &= 0xff;
24522452

24532453
if (extract_type < EXTR_OVERWRITE || extract_type > EXTR_IF_EXISTS) {
2454-
zend_throw_error(NULL, "Invalid extract type");
2454+
zend_value_error("Invalid extract type");
24552455
return;
24562456
}
24572457

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

24632463
if (prefix) {
24642464
if (ZSTR_LEN(prefix) && !php_valid_var_name(ZSTR_VAL(prefix), ZSTR_LEN(prefix))) {
2465-
zend_throw_error(NULL, "Prefix is not a valid identifier");
2465+
zend_value_error("Prefix is not a valid identifier");
24662466
return;
24672467
}
24682468
}
@@ -2619,7 +2619,7 @@ PHP_FUNCTION(array_fill)
26192619

26202620
if (EXPECTED(num > 0)) {
26212621
if (sizeof(num) > 4 && UNEXPECTED(EXPECTED(num > 0x7fffffff))) {
2622-
zend_throw_error(NULL, "Too many elements");
2622+
zend_value_error("Too many elements");
26232623
return;
26242624
} else if (UNEXPECTED(start_key > ZEND_LONG_MAX - num + 1)) {
26252625
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
@@ -2668,7 +2668,7 @@ PHP_FUNCTION(array_fill)
26682668
} else if (EXPECTED(num == 0)) {
26692669
RETURN_EMPTY_ARRAY();
26702670
} else {
2671-
zend_throw_error(NULL, "Number of elements can't be negative");
2671+
zend_value_error("Number of elements can't be negative");
26722672
return;
26732673
}
26742674
}
@@ -2706,7 +2706,7 @@ PHP_FUNCTION(array_fill_keys)
27062706
#define RANGE_CHECK_DOUBLE_INIT_ARRAY(start, end) do { \
27072707
double __calc_size = ((start - end) / step) + 1; \
27082708
if (__calc_size >= (double)HT_MAX_SIZE) { \
2709-
zend_throw_error(NULL, \
2709+
zend_value_error(\
27102710
"The supplied range exceeds the maximum array size: start=%0.0f end=%0.0f", end, start); \
27112711
return; \
27122712
} \
@@ -2718,7 +2718,7 @@ PHP_FUNCTION(array_fill_keys)
27182718
#define RANGE_CHECK_LONG_INIT_ARRAY(start, end) do { \
27192719
zend_ulong __calc_size = ((zend_ulong) start - end) / lstep; \
27202720
if (__calc_size >= HT_MAX_SIZE - 1) { \
2721-
zend_throw_error(NULL, \
2721+
zend_value_error(\
27222722
"The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT, end, start); \
27232723
return; \
27242724
} \
@@ -2816,7 +2816,7 @@ PHP_FUNCTION(range)
28162816
high = zval_get_double(zhigh);
28172817

28182818
if (zend_isinf(high) || zend_isinf(low)) {
2819-
zend_throw_error(NULL, "Invalid range supplied: start=%0.0f end=%0.0f", low, high);
2819+
zend_value_error("Invalid range supplied: start=%0.0f end=%0.0f", low, high);
28202820
return;
28212821
}
28222822

@@ -2909,7 +2909,7 @@ PHP_FUNCTION(range)
29092909
}
29102910
err:
29112911
if (err) {
2912-
zend_throw_error(NULL, "step exceeds the specified range");
2912+
zend_value_error("step exceeds the specified range");
29132913
return;
29142914
}
29152915
}
@@ -4389,7 +4389,7 @@ PHP_FUNCTION(array_pad)
43894389
input_size = zend_hash_num_elements(Z_ARRVAL_P(input));
43904390
pad_size_abs = ZEND_ABS(pad_size);
43914391
if (pad_size_abs < 0 || pad_size_abs - input_size > Z_L(1048576)) {
4392-
zend_throw_error(NULL, "You may only pad up to 1048576 elements at a time");
4392+
zend_value_error("You may only pad up to 1048576 elements at a time");
43934393
return;
43944394
}
43954395

@@ -5769,7 +5769,7 @@ PHP_FUNCTION(array_multisort)
57695769
array_size = zend_hash_num_elements(Z_ARRVAL_P(arrays[0]));
57705770
for (i = 0; i < num_arrays; i++) {
57715771
if (zend_hash_num_elements(Z_ARRVAL_P(arrays[i])) != (uint32_t)array_size) {
5772-
zend_throw_error(NULL, "Array sizes are inconsistent");
5772+
zend_value_error("Array sizes are inconsistent");
57735773
MULTISORT_ABORT;
57745774
}
57755775
}
@@ -5865,7 +5865,7 @@ PHP_FUNCTION(array_rand)
58655865
num_avail = zend_hash_num_elements(Z_ARRVAL_P(input));
58665866

58675867
if (num_avail == 0) {
5868-
zend_throw_error(NULL, "Array is empty");
5868+
zend_value_error("Array is empty");
58695869
return;
58705870
}
58715871

@@ -5906,7 +5906,7 @@ PHP_FUNCTION(array_rand)
59065906
}
59075907

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

@@ -6395,7 +6395,7 @@ PHP_FUNCTION(array_chunk)
63956395

63966396
/* Do bounds checking for size parameter. */
63976397
if (size < 1) {
6398-
zend_throw_error(NULL, "Size parameter expected to be greater than 0");
6398+
zend_value_error("Size parameter expected to be greater than 0");
63996399
return;
64006400
}
64016401

@@ -6460,7 +6460,7 @@ PHP_FUNCTION(array_combine)
64606460
num_values = zend_hash_num_elements(values);
64616461

64626462
if (num_keys != num_values) {
6463-
zend_throw_error(NULL, "Both parameters should have an equal number of elements");
6463+
zend_value_error("Both parameters should have an equal number of elements");
64646464
return;
64656465
}
64666466

ext/standard/assert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ PHP_FUNCTION(assert_options)
314314
break;
315315

316316
default:
317-
zend_throw_error(NULL, "Unknown value " ZEND_LONG_FMT, what);
317+
zend_value_error("Unknown value " ZEND_LONG_FMT, what);
318318
break;
319319
}
320320

ext/standard/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ PHP_FUNCTION(scandir)
559559
ZEND_PARSE_PARAMETERS_END();
560560

561561
if (dirn_len < 1) {
562-
zend_throw_error(NULL, "Directory name cannot be empty");
562+
zend_value_error("Directory name cannot be empty");
563563
return;
564564
}
565565

ext/standard/string.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -931,12 +931,12 @@ PHP_FUNCTION(wordwrap)
931931
}
932932

933933
if (breakchar_len == 0) {
934-
zend_throw_error(NULL, "Break string cannot be empty");
934+
zend_value_error("Break string cannot be empty");
935935
return;
936936
}
937937

938938
if (linelength == 0 && docut) {
939-
zend_throw_error(NULL, "Can't force cut when width is zero");
939+
zend_value_error("Can't force cut when width is zero");
940940
return;
941941
}
942942

@@ -1143,7 +1143,7 @@ PHP_FUNCTION(explode)
11431143
ZEND_PARSE_PARAMETERS_END();
11441144

11451145
if (ZSTR_LEN(delim) == 0) {
1146-
zend_throw_error(NULL, "Empty delimiter");
1146+
zend_value_error("Empty delimiter");
11471147
return;
11481148
}
11491149

@@ -1642,7 +1642,7 @@ PHP_FUNCTION(dirname)
16421642
ZSTR_LEN(ret) = zend_dirname(ZSTR_VAL(ret), str_len);
16431643
#endif
16441644
} else if (levels < 1) {
1645-
zend_throw_error(NULL, "Invalid argument, levels must be >= 1");
1645+
zend_value_error("Invalid argument, levels must be >= 1");
16461646
zend_string_efree(ret);
16471647
return;
16481648
} else {
@@ -2155,7 +2155,7 @@ PHP_FUNCTION(chunk_split)
21552155
ZEND_PARSE_PARAMETERS_END();
21562156

21572157
if (chunklen <= 0) {
2158-
zend_throw_error(NULL, "Chunk length should be greater than zero");
2158+
zend_value_error("Chunk length should be greater than zero");
21592159
return;
21602160
}
21612161

@@ -5322,7 +5322,7 @@ PHP_FUNCTION(str_repeat)
53225322
ZEND_PARSE_PARAMETERS_END();
53235323

53245324
if (mult < 0) {
5325-
zend_throw_error(NULL, "Second argument has to be greater than or equal to 0");
5325+
zend_value_error("Second argument has to be greater than or equal to 0");
53265326
return;
53275327
}
53285328

@@ -5569,7 +5569,7 @@ PHP_FUNCTION(substr_count)
55695569
ZEND_PARSE_PARAMETERS_END();
55705570

55715571
if (needle_len == 0) {
5572-
zend_throw_error(NULL, "Empty substring");
5572+
zend_value_error("Empty substring");
55735573
return;
55745574
}
55755575

@@ -5646,12 +5646,12 @@ PHP_FUNCTION(str_pad)
56465646
}
56475647

56485648
if (pad_str_len == 0) {
5649-
zend_throw_error(NULL, "Padding string cannot be empty");
5649+
zend_value_error("Padding string cannot be empty");
56505650
return;
56515651
}
56525652

56535653
if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH) {
5654-
zend_throw_error(NULL, "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH");
5654+
zend_value_error("Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH");
56555655
return;
56565656
}
56575657

@@ -5911,7 +5911,7 @@ PHP_FUNCTION(str_word_count)
59115911
/* nothing to be done */
59125912
break;
59135913
default:
5914-
zend_throw_error(NULL, "Invalid format value " ZEND_LONG_FMT, type);
5914+
zend_value_error("Invalid format value " ZEND_LONG_FMT, type);
59155915
return;
59165916
}
59175917

@@ -6028,7 +6028,7 @@ PHP_FUNCTION(str_split)
60286028
ZEND_PARSE_PARAMETERS_END();
60296029

60306030
if (split_length <= 0) {
6031-
zend_throw_error(NULL, "The length of each segment must be greater than zero");
6031+
zend_value_error("The length of each segment must be greater than zero");
60326032
return;
60336033
}
60346034

@@ -6107,7 +6107,7 @@ PHP_FUNCTION(substr_compare)
61076107
if (len == 0) {
61086108
RETURN_LONG(0L);
61096109
} else {
6110-
zend_throw_error(NULL, "The length must be greater than or equal to zero");
6110+
zend_value_error("The length must be greater than or equal to zero");
61116111
return;
61126112
}
61136113
}

ext/standard/tests/array/array_chunk2.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ $input_array = array('a', 'b', 'c', 'd', 'e');
66

77
try {
88
var_dump(array_chunk($input_array, 0));
9-
} catch (\Error $e) {
9+
} catch (\ValueError $e) {
1010
echo $e->getMessage() . "\n";
1111
}
1212

1313
try {
1414
var_dump(array_chunk($input_array, 0, true));
15-
} catch (\Error $e) {
15+
} catch (\ValueError $e) {
1616
echo $e->getMessage() . "\n";
1717
}
1818

ext/standard/tests/array/array_chunk_variation5.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,22 @@ foreach ($sizes as $size){
2929
echo "\n-- Testing array_chunk() when size = $size --\n";
3030
try {
3131
var_dump( array_chunk($input_array, $size) );
32-
} catch (\Error $e) {
32+
} catch (\ValueError $e) {
3333
echo $e->getMessage() . "\n";
3434
}
3535
try {
3636
var_dump( array_chunk($input_array, $size, true) );
37-
} catch (\Error $e) {
37+
} catch (\ValueError $e) {
3838
echo $e->getMessage() . "\n";
3939
}
4040
try {
4141
var_dump( array_chunk($input_array, $size, false) );
42-
} catch (\Error $e) {
42+
} catch (\ValueError $e) {
4343
echo $e->getMessage() . "\n";
4444
}
4545
}
4646
?>
4747

48-
DONE
4948
--EXPECT--
5049
*** Testing array_chunk() : usage variations ***
5150

@@ -146,5 +145,3 @@ array(3) {
146145
int(3)
147146
}
148147
}
149-
150-
DONE

ext/standard/tests/array/array_combine_error2.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,27 @@ var_dump( array_combine(array(), array()) );
1818
echo "\n-- Testing array_combine() function with empty array for \$keys argument --\n";
1919
try {
2020
var_dump( array_combine(array(), array(1, 2)) );
21-
} catch (\Error $e) {
21+
} catch (\ValueError $e) {
2222
echo $e->getMessage();
2323
}
2424

2525
// Testing array_combine by passing empty array to $values
2626
echo "\n-- Testing array_combine() function with empty array for \$values argument --\n";
2727
try {
2828
var_dump( array_combine(array(1, 2), array()) );
29-
} catch (\Error $e) {
29+
} catch (\ValueError $e) {
3030
echo $e->getMessage();
3131
}
3232

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

4141
?>
42-
43-
DONE
4442
--EXPECT--
4543
*** Testing array_combine() : error conditions specific to array_combine() ***
4644

@@ -54,4 +52,3 @@ Both parameters should have an equal number of elements
5452
Both parameters should have an equal number of elements
5553
-- Testing array_combine() function by passing array with unequal number of elements --
5654
Both parameters should have an equal number of elements
57-
DONE

ext/standard/tests/array/array_fill_error.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ $val = 1;
1717

1818
try {
1919
var_dump( array_fill($start_key,$num,$val) );
20-
} catch (Error $e) {
20+
} catch (\ValueError $e) {
2121
echo $e->getMessage() . "\n";
2222
}
2323

2424
?>
25-
26-
DONE
27-
--EXPECTF--
25+
--EXPECT--
2826
*** Testing array_fill() : error conditions ***
2927
Number of elements can't be negative
30-
31-
DONE

ext/standard/tests/array/array_multisort_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ echo "\n-- Testing array_multisort() function with repeated flags --\n";
1414
$ar1 = array(1);
1515
try {
1616
var_dump( array_multisort($ar1, SORT_ASC, SORT_ASC) );
17-
} catch (Error $e) {
17+
} catch (\TypeError $e) {
1818
echo $e->getMessage() . "\n";
1919
}
2020

2121
echo "\n-- Testing array_multisort() function with repeated flags --\n";
2222
$ar1 = array(1);
2323
try {
2424
var_dump( array_multisort($ar1, SORT_STRING, SORT_NUMERIC) );
25-
} catch (Error $e) {
25+
} catch (\TypeError $e) {
2626
echo $e->getMessage() . "\n";
2727
}
2828

ext/standard/tests/array/array_multisort_variation1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ foreach($inputs as $key =>$value) {
9999
echo "\n--$key--\n";
100100
try {
101101
var_dump( array_multisort($value));
102-
} catch (Error $e) {
102+
} catch (\ValueError | \TypeError $e) {
103103
echo $e->getMessage() . "\n";
104104
}
105105
};

0 commit comments

Comments
 (0)